首页 > 解决方案 > 有机会的记号

问题描述

我是 Python 新手,所以请帮忙。如果密码错误,我希望它减少机会。如果我输入错误的密码,它会卡在 2

while True:
    password = input("Password for activation ")
    chance = 3

    if password == "LUN":
            print("access granted")
            break

    if password != "LUN":
        wrong = chance - 1
        print("Try again. your chance is {0}".format(wrong))

    if chance == 0:
        break

标签: python

解决方案


你有chance = 3你的while循环。所以每个循环,机会都会回到 3。


推荐阅读