1 # Author : Mamba 2 3 #python基础一之课后作业:编写登录接口 4 5 # 输入用户名密码 6 # 认证成功后显示欢迎信息 7 # 用户名3次输入错误后,退出程序 8 # 密码3次输入错误后,锁定用户名 9 print("------mamba_login------") 10 user = input("please input your username :") 11 12 pwd = 0 13 user_count = 0 14 pwd_count =0 15 isEnd = False 16 17 while user_count < 3 : #当输入的用户名数据小于3次时 18 if isEnd: 19 break 20 if user == "mamba": 21 pwd = input("please input your password :") 22 while pwd_count < 3: #当输入的密码小于3次时 23 if pwd == "123": 24 print("welcome mamba come back") 25 isEnd = True 26 break 27 else: 28 pwd_count += 1 29 if 3 != pwd_count: 30 print('{0} {1} {2} {3}'.format('Password is wrong!!!', 'you have', (3 - pwd_count), 'chances.')) 31 pwd = input("please input your password again:") 32 else: #当用户名不对 33 user_count += 1 34 if 3 != user_count: 35 print('{0} {1} {2} {3}'.format('Username is wrong!!!', 'you have', (3 - user_count), 'chances.')) 36 user = input("please input your username again: ") 37 if user_count > 3 or pwd_count > 3 or isEnd == False : #当用户名或密码的次数超过3次 38 print("Wrong!!sorry.") 39 print("you have tried too many times ,game over")
浙公网安备 33010602011771号