有文件t1.txt里面的内容为:(5分)
1,alex,22,13651054608,IT
2,wusir,23,13304320533,Tearcher
3,taibai,18,1333235322,IT
利用文件操作,将其构造成如下数据类型。
[{'id':'1','name':'alex','age':'22','phone':'13651054608','job':'IT',{'id':'2','name':'wusir','age':'23','phone':'13304320533','job':'Tearcher'},{'id':'3','name':'taibai','age':'18','phone':'1333235322','job':'IT'}]
有如下车牌和车辆归属地,形成一个新的字典,显示每个归属地的车辆共有多少:(8分)
cars = ['鲁A32444','鲁A12333','湘B8989M','⿊A49678','⿊B46555','沪B25044','冀A11111',"京A01101"]
locals = {'冀':{"A":"石家庄","B":"唐山"},
'⿊':{"A":"哈尔滨","B":"齐齐哈尔"},
'鲁':{"A":"济南","B":"青岛"},
'鄂':{"A":"武汉","B":"黄石"},
'湘':{"A":"长沙","B":"株洲"},
}
dic={}
l1=[]
for i in cars:
if locals.get(i[0]):
if locals.get(i[0]).get(i[1]) not in dic:
dic[locals.get(i[0]).get(i[1])]=1
else:
dic[locals.get(i[0]).get(i[1])] += 1
print(dic)
userinfo.txt 文件中存放以下结构:(总分8分)
alex:alex3714
wusir:123456
meet:meet123
让用户选择:
1.注册
2.登录
2.用户选择注册就将账号和密码添加到userinfo.txt中,如果用户名存在就提示用户名存在,不存在就进行添加(2分)
3.用户选择登录,就验证用户的账号和密码是否与userinfo.txt一致,如果一致终止循环提示登录成功(3分)
4.让用户登录三次,三次错误将用户进行锁定提示用户名已锁定,并打印错误次数(使用字符串格式化)(3分)
def f(x,l=[]):
for i in range(x):
l.append(i*i)
print(l)
f(2)
f(3,[3])
f(4,[])
# v1 = '人生苦短,我用Python'
# v2 = [1, 2, 3, 4, v1]
# v1 = "人生苦短,用毛线Python"
# print(v2)
info = [1, 2, 3]
userinfo = {'account': info, 'num': info, 'money': info}
info.append(9)
print(userinfo)
info = "题怎么这么多"
print(userinfo)
# info = [1, 2, 3]
# userinfo = [info, info, info, info, info]
#
# info[0] = '不仅多,还特么难呢'
# print(info, userinfo)
# data = {}
# for i in range(10):
# data['user'] = i
# print(data)
# data_list = []
# data = {}
# for i in range(10):
# data['user'] = i
# data_list.append(data)
# print(data_list)
data_list = []
for i in range(10):
data = {}
data['user'] = i
data_list.append(data)
print(data_list)
v1 = [1,2,3,4,5,6,7,8,9]
v2 = {}
for item in v1:
if item < 6:
continue
if 'k1' in v2:
v2['k1'].append(item)
else:
v2['k1'] = [item ]
print(v2)