我正在尝试使用 python 和 sqlite 制作密码管理器。我将变量设置为 0 并在每次用户输入错误密码时将其递增 1,一旦变量x等于 3,程序应关闭,但变量x仅递增 1 次,然后保持为 1。我该如何解决这个问题?
master = 'pass'
def main():
inp = input("\nPassword\n>>> ")
global x
x = 0
if inp == master:
print("Welcome Back!\n")
print("1. View Database\n2. Edit Database\n")
task = input(">>> ")
if task == 0:
pass
else:
pass
else:
if x == 3:
print("You have failed to enter the correct password 3 times")
os.exit()
else:
x += 1
print(x)
main()
main()