Day2,入坑第二天

作业:

代码如下:

待读取的文件存储的用户名和密码为:
rzf,123456
ren,000000
 
函数内容如下:
 
def login_in():
    count = 0
    while True:
        user = []
        psw = []
        for line in open('D:/user.txt', "r", encoding="utf-8-sig"):
            line = line.strip("\n")
            list = line.split(',')
            user.append(list[0])
            psw.append(list[1])
        user1 = input('输入用户名:').strip()
        if user1 in user:
            psw1 = input('输入密码:').strip()
            if psw1 in psw:
                print('Login succeed!')
                count = 0
            else:
                print("password isn't correct,please input again(剩余%s次机会):" %(2-count))
                count+=1
        else:
            print("username isn't correct,please input again(剩余%s次机会):" %(2-count))
            count+=1
        if count == 3:
            print('输入次数已达上限!')
            break
login_in()

猜你喜欢

转载自www.cnblogs.com/renzhenfeng/p/11013459.html