标签:result name put word span input inpu += logs
一、用户只有三次登录机会。
username = ‘莉莉‘ password = ‘1220‘ i = 0 while i < 3: name = input(‘请输入你的用户名:‘) pwd = input(‘请输入你的密码:‘) if name == username and pwd == password: print(‘登录成功‘) break else: print(‘登录失败,还有%d次登录机会‘%(2-i)) if (2-i) == 0 : break i += 1
二、当剩余机会为0时,可以询问用户是否在试试,如果用户同意在尝试,那就将在给他三次机会。
username = ‘莉莉‘ password = ‘1220‘ i = 0 while i < 3: name = input(‘请输入你的用户名:‘) pwd = input(‘请输入你的密码:‘) if name == username and pwd == password: print(‘登录成功‘) break else: print(‘登录失败,还有%d次登录机会‘%(2-i)) if (2-i) == 0 : result = input(‘是否再试试?Y or N‘) if result == ‘Y‘: i = 0 continue if result == ‘N‘: i = 3 continue i += 1 else: print(‘再见‘)
标签:result name put word span input inpu += logs
原文地址:http://www.cnblogs.com/jassin-du/p/7699297.html