每天努力一点点,坚持下去 ------ 博客首页

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('账户不存在')

 

posted @ 2020-01-21 22:08  他还在坚持嘛  阅读(182)  评论(0编辑  收藏  举报