Python-day1 登陆作业
# 1、写一个登录的程序, # 1、最多登陆失败3次 # 2、登录成功,提示欢迎xx登录,今天的日期是xxx,程序结束 # 3、要检验输入是否为空, 账号和密码不能为空 # 4、账号不区分大小写 import time users = {} time = time.strftime('%Y-%m-%d %H:%M:%S') with open('user.txt')as fr: for line in fr: line = line.strip('\n') #读出来会有换行符,需要去掉 if line.strip(): user,pwd = line.split(',') users[user] = pwd while True: username = input('请输入账号:').lower().strip() password = input('请输入密码:').strip() if username == '' and password == '': print('不能为空') elif username in users: if password != users.get(username): print('%s登录成功,今天的日期是%s' % (username,time)) break else: print('密码不对') else: print('账户不存在')
本文来自博客园,作者:他还在坚持嘛,转载请注明原文链接:他还在坚持嘛 https://www.cnblogs.com/brf-test/p/12227179.html