#多维数组
list = [[87,57,98],[34,87,90]]
print(list[1][0])
l = [[87,57,98],[34,87,[90,99,67]]]
print(l[1][2][1])
#字典 key-value
flightplan = {'flight':'2019-10-26','dep':'重庆','arr':'杭州','flightno':'CA1889'}
print(flightplan['flightno'])
print(flightplan['flight'])
print(flightplan.get('dep'))
print(flightplan.get('arr'))
flightplan['deptime'] = '0900'
flightplan.setdefault('arrtime','1000')
print(flightplan)
#增加
flightplan['flightno'] = 'CA1234' #中括号方式增加,若该字段已经存在,会修改原有字段的参数值
print(flightplan)
flightplan.setdefault('flightno','CA1998') #中括号方式增加,若该字段已经存在,原有参数值不变
print(flightplan)
#修改
flightplan['dep'] = '成都'
flightplan.update(arr = '曼谷')
print(flightplan)
#删除
flightplan.pop('deptime')
print(flightplan)
#注册
# 1、输入用户名、密码、确认密码
# 2、判断输入的有效性
# 3、若有效,数据新增
# 4、若超过输入次数,退出
users = {}
for i in range(3):
username = input('请输入用户名:')
passwd = input('请输入用户名:')
apasswd = input('请输入用户名:')
if username in users.keys():
print('用户名已存在')
elif len(username) == 0 or len(passwd) == 0 or len(apasswd) == 0:
print('存在必填项为空')
elif username.isspace() or passwd.isspace() or apasswd.isspace():
print('存在必填项为空')
else:
if passwd != apasswd:
print('请输入相同的密码')
else:
users[username] = passwd
print('注册成功',users)
#登录
# 1、判断用户名是否存在
# 2、若存在、判断密码是否正确
# 3、若超过输入次数、退出
for j in range(3):
username = input('请输入用户名:')
passwd = input('请输入用户名:')
if username not in users:
print('用户名或密码错误')
else:
if passwd != users.get(username):
print('用户名或密码错误')
else:
print('登录成功')
break
if j == 2:
print('错误次数过多,已锁定')
break
len(info['xioayuan']['cars']['china'])