可能重複:
python, basic question on loops
how to let a raw_input repeat until I wanna quit?的Python - 循環的輸入
我想一些幫助的Python請。
我在Py2.7.2中編寫程序,但遇到一些問題。
我有什麼到目前爲止是這樣的:
choice = raw_input("What would you like to do")
if choice == '1':
print("You chose 1")
elif choice == '2':
print("You chose 2")
elif choice == '3':
print("You chose 3")
else:
print("That is not a valid input.")
但用戶選擇是1,2,3或4後,程序會自動退出。有沒有一種方法可以讓程序循環備份,以便再次詢問他們「您想要做什麼?」;並且這樣繼續發生,直到用戶退出程序。