我正在爲遊戲或其他東西或其他代碼編寫一個模擬註冊頁面,在代碼結尾處我想確認用戶輸入的數據是否正確。我通過鍵入來做到這一點。如何從一開始循環一個程序
#User sign up page.
#Getting the user's information.
username = input ("Plese enter your first name here: ")
userage = input ("Please enter your age here: ")
userphoneno = input ("Please enter your home or mobile number here: ")
#Showing the inforamtion.
print ("\nIs the following correct?\n")
print ("•Name:",username)
print ("•Age:",userage)
print ("•Phone Number:",userphoneno)
#Confirming the data.
print ("\nType Y for yes, and N for no. (Non-case sensitive.)")
answer = input ("• ")
if answer == 'Y'or'y':
print ("Okay, thank you for registering!")
break
else:
#Restart from #Getting the user's information.?
我的問題出現在代碼的最後一節。當輸入「Y或y」時程序就會正常結束,但如果輸入「N或n」,我似乎無法解決如何讓用戶輸入數據。我嘗試了一個While循環,我猜是解決方案,但我似乎無法讓它正常工作。
任何幫助將不勝感激。謝謝!
向我們展示您嘗試的while循環?另外,答案=='Y'or'y''將始終評估爲真。看看[這](http://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple-values)。 –