我遇到了這個數據驗證程序的問題,我有一個任務。由於某些原因,我在這個while循環中遇到了麻煩,它繼續無限期地運行。其他while循環在我的代碼運行正常的,但在這裏這個功能不...while循環以及如何在函數中停止它
def menu():
pick = None
while pick != "q" or pick != "Q":
print """
\n
Welcome to my password validation program.
1 - New Account
2 - Login
q - Quit
"""
pick = raw_input("What do you want to do?: ")
# Quit
if pick == "q":
print "\t Thanks for coming Good-bye."
raw_input("\nPress any key to exit")
# New Account
elif pick == "1":
main()
# Login
elif pick == "2":
if ps == 100:
login()
else:
print "Sorry no password has been set. please create a new account."
else:
print "Sorry, but", pick, "isn't a valid choice."
menu()
有大約走錯了路的代碼,無論是你的答案是正確的。 @jonrsharpe @tdelaney
def menu():
print \
"""
\n
Welcome to my password validation program.
1 - New Account
2 - Login
q - Quit
"""
pick = None
pick = raw_input("What do you want to do?: ")
# Quit
if pick == "q":
print "\t Thanks for coming Good-bye."
raw_input("\nPress any key to exit")
# New Account
elif pick == "1":
main()
# Login
elif pick == "2":
if ps == 100:
login()
else:
print "Sorry no password has been set. please create a new account."
else:
print "Sorry, but", pick,"isn't a valid choice."
menu()
你意識到只有'print'行在while循環中? – jonrsharpe
那麼這是如何阻止無限循環的呢?我知道打印行會打印出下面的文字,但它與無限循環有什麼關係 – Will
***只有* print'行**其中**不會改變'pick'的值* *。你的函數的其餘部分只在循環結束後運行*,它不能*。 – jonrsharpe