python--用户登录(简易版)
#一、简易版用户登录,此程序直到用户输入正确的用户名和密码,不然不会退出
1 _name = "liangchen" 2 _passwd = "abc123" 3 while True: 4 username = input("username:") 5 password = input("password:") 6 if username == _name and password == _passwd: 7 print("welcome %s login"%_name) 8 break 9 else: 10 print("Invalid username or password!")
#二、简易版用户登录,用户输入正确的用户名和密码或者用户输入三次错误都会退出登录 _name = "liangchen" _passwd = "abc123" login_time = 0 while login_time<3: username = input("username:") password = input("password:") if username == _name and password == _passwd: print("welcome %s login"%_name) break else: print("Invalid username or password!") login_time += 1 if(login_time == 3): print("输入次数过多,退出登录!") break