我正在尝试让我的代码要求输入密码并接收它,如果密码正确,则会发生某些事情,如果不是,则会发生其他事情,当我尝试我的代码时,它在第 10 行和第 18 行给我一个错误:
if (password == 'xxxx'):
UnboundLocalError: local variable 'password' referenced before assignment
这是代码:
import random
def askforPassword():
print('Welcome to the Machine!')
print('Enter the password: ')
password = input()
def getPassword():
while passwordTry != 0:
if (password == 'xxxx'):
print('Correct')
else:
passwordTry -= 1
print('INCORRECT!')
passwordTry = 5
askforPassword()
getPassword()