无线循环:
#__author:"hanhankeji" #date: 2019/11/28 # while 后面可以加 else user = "hanhankeji" password = "abc123" counter = 0 while counter < 3 : Username = input("请输入用户名:") UserPassword = input("请输入密码:") if Username == user and UserPassword == password: print("欢迎用户登录!") break else: print("账户或密码错误,请确认!" + "你还有" + str(3 - int(counter) - 1) + "次机会") counter += 1 if counter == 3: keep_going_choice = input("是不是再试试3次[y/n]:") if keep_going_choice =="y": counter = 0 else: print("要不要脸·输了3次都 不对")
原文:https://www.cnblogs.com/hanhankeji/p/11949357.html