我現在已經更改了我的代碼,但是在那裏說最後一行的語法無效,我該如何解決這個問題?我改變了最後一行的全球地位displayMenu之前,但它似乎是引起問題,以我的代碼當我使用input()時,我的代碼在我運行時沒有出現
users = {}
status = ""
def displayMenu():
status = raw_input("Are you a registered user? y/n? Press q to quit: ")
if status == "y":
oldUser()
elif status == "n":
newUser()
def newUser():
createLogin =("Create login name: ")
if createLogin in users: # check if login name exists
print ("\nLogin name already exist!\n")
else:
createPassw =("Create password: ")
users[createLogin] = createPassw # add login and password
print("\nUser created!\n")
def oldUser():
login = raw_input("Enter login name: ")
passw = raw_input("Enter password: ")
# check if user exists and login matches password
if login in users and users[login] == passw:
print ("\nLogin successful!\n")
else:
print ("\nUser doesn't exist or password error!\n")
if passw == users[login]:
print ("Login successful!\n")
while status != "q":
global status displayMenu():
你使用Python 3還是Python 2?如果你仍然在使用Python 2,你應該使用'raw_input',Python 2'input'函數是危險的。在Python 3中,舊的'input'函數不再存在,'raw_input'已被重命名爲'input'。 –
它看起來像你使用Python 2,所以你應該認真考慮升級到Python 3.同時,改變'status = input()(「你是註冊用戶嗎?y/n?按q退出:」 )'回到'status = raw_input(「你是註冊用戶嗎?y/n?按q退出:」)'。你需要以同樣的方式修復那些'input()'行。 –
謝謝我現在發佈了一個編輯,因爲它似乎有另一個問題 –