三次登陆
基础版
n = 3 while n > 0: username = input('请输入用户名') pwd = input('请输入密码') if username == 'xiaoqiang' and pwd == '123': print('登陆成功') break else: print('登陆失败') n -= 1 print('输入错误,你还有%s机会' % n)
函数版
def login(): n = 3 while n > 0: username = input('请输入用户名') pwd = input('请输入密码') if username == 'xiaoqiang' and pwd == '123': print('登陆成功') break else: print('登陆失败') n -= 1 print('输入错误,你还有%s机会' % n)