Python
#账号注册登录
username = input("用户名:")
password = input("密码:")
with open('list_info',mode='w+',encoding='utf-8') as file:
file.write('{}\n{}'.format(username,password))
print("欢迎登录,注册成功!!!")
lis = []
i = 0
while i < 3:
usr = input("用户名:")
pwd = input("密码:")
with open('list_info', mode='r+', encoding='utf-8') as F:
# print(F.read())
for line in F:
lis.append(line)
print(lis)
if usr == lis[0].strip() and pwd == lis[1].strip():
print("成功登录")
break
else:
print("密码错误")
i += 1
if i == 3:
print('输错三次!')
########################################################
#如下值li = [11,22,33,44,55,77,88,99,90],将所有大于66的值保存至字典的第一个key中,将小于66的值保存至第二个key的值中
li = [11,22,33,44,55,77,88,99,90]
res = {}
for row in li:
if row > 66:
if 'key1' not in res:
res['key1'] = []
res['key1'].append(row)
else:
if 'key2' not in res:
res['key2'] = []
res['key2'].append(row)
print(res)
for row in li:
if row > 66:
res.setdefault('key1',[])
res['key1'].append(row)
else:
res.setdefault('key2',[])
res['key2'].append(row)
print(res)
###########################################################
#content = input('请输入内容:')如7+8+9....两个以上数字,然后相加,dic={'相加结果':}表示:
content = input('请输入内容:')
content_list = content.split('+')
sum = 0
for i in content_list:
sum = sum + int(i)
dic = {}
dic.setdefault('请输入内容:', sum)
print(dic)
#######################################################
#输入用户名密码,用户名q或Q就退出,如果用户名有'张三','李小四','王二麻子'就用“*”等数量替换,每次输入完成打印添加的用户名和密码,和所有的,退出后打印所有的用户名和密码:
user_list =[
{'username':'barry','password':'1234'},
{'username':'alex','password':'asdf'},
]
board = ['张三','李小四','王二麻子']
while 1:
username = input('输入用户名:')
if username.upper() == 'Q':
break
password = input('输入密码:')
for i in board:
if i in username:
username = username.replace(i,'*'*len(i))
user_list.append({'username':username,'password':password})
print({'username':username,'password':password})
print(user_list)
print(user_list)
posted on 2021-04-01 13:37 kakajiejie 阅读(44) 评论(0) 编辑 收藏 举报