i=3 username = "xzy" password = "123456" while i>0: name = input("请输入你的用户名:") i -= 1 if name == username: passwd = input("请输入密码:") if passwd == password: print("登录成功,请稍候") print('''恭喜你登录成功 欢迎进入 用户名: %s 密 码: %s ''' % (username,password)) break else: if i == 0: print('你的机会已经用完') answer = input('你是否再试试 ? Y or N') if answer == 'Y': i = 3 else: print("本次操作结束!") break print('你的密码错误,请重新输入') print('你还有' + str(i) + '次机会') else: if i == 0: print('你的机会已经用完') answer = input('你是否再试试 ? Y or N') if answer == 'Y': i = 3 else: print("本次操作结束!") break print("请输入正确的用户名!") print('你还有%s次机会' % (i)) else: print('你要不要脸!')