码迷,mamicode.com
首页 > 编程语言 > 详细

python3作业:模拟登录

时间:2017-02-22 13:05:08      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:open   处理   用户信息   input   else   print   txt   custom   pre   

__author__ = "bin007"

customer = {}#存储用户信息
#处理用户信息文件
try:
with open(‘login.txt‘,‘r‘,encoding=‘utf-8‘) as f:
for line in f:
customer[line.split()[0]] = [line.split()[1],line.split()[2]]
except:
print(‘用户文件不存在‘)

login_name = input("\033[32;1m请输入用户名-->:\033[0m") #获取用户名
login_secret = input(‘\033[32;1m请输入密码--->:\033[0m‘) #获取用户密码
if customer.get(login_name):
customer_secret = customer.get(login_name)[0]
secret_err = int(customer.get(login_name)[1])
if secret_err < 3:
if login_secret == customer_secret:
print(‘\033[32;1m登录成功\033[0m‘)
else:
print(‘\033[31;1m用户名或密码错误,还剩余%s次机会\033[0m‘%(2-secret_err))
customer.get(login_name)[1] = str(int(customer.get(login_name)[1])+1)
else:
print(‘\033[41;1m用户已被锁定\033[0m‘)
customer.get(login_name)[1] = str(int(customer.get(login_name)[1])+1)
print(customer.get(login_name)[1])
else:
login_new = input(‘\033[31;1m用户不存在是否以当前用户名密码注册(Y/N):\033[0m‘)
if login_new == ‘Y‘ or login_new == ‘y‘:
customer[login_name] = [login_secret,0]
print(‘\033[32;1m注册成功,请登录\033[0m‘)
else:
pass
#更新用户文件
with open(‘login.txt‘,‘w+‘,encoding=‘utf-8‘) as f:
for i in customer:
write_line = (‘%s %s %s‘+‘\n‘)% (i,customer[i][0],customer[i][1])
f.write(write_line)


python3作业:模拟登录

标签:open   处理   用户信息   input   else   print   txt   custom   pre   

原文地址:http://www.cnblogs.com/roc-fly/p/6428070.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!