我正在嘗試創建子菜單的主菜單。我想這樣做,無論用戶從主菜單選擇子菜單的順序如何,他們最終都會被引導回主菜單 - 也就是說,直到他們選擇最後一個選項(3.保持並結束轉動) 。如何循環有python子菜單的菜單?
這是我陷入困境。目前,用戶只能瀏覽一次菜單序列。我如何使這個重複循環?
#main menu
playermenumain=raw_input("What would you like to do?\n (1) Buy\n (2)Sell\n (3)Hold and end turn ")
if playermenumain=="1":
buyermenu=raw_input("In what area would you like to buy?"\n (1)Stocks\n (2) Bonds\ (3) Nevermind\n)
if buyermenu=="1":
stockamount=stockamount+500
elif buyermenu=="2":
bondamount=bondamount+500
else:
buyermenu=raw_input("In what area would you like to buy?"\n (1)Stocks\n (2) Bonds\ (3) Nevermind\n)
if playermenumain=="2":
sellermenu=raw_input("In what area would you like to buy?"\n (1)Stocks\n (2) Bonds\ (3) Nevermind\n)
if sellermenu=="1":
stockamount=stockamount-500
elif sellermenu=="2":
bondamount=bondamount-500
else:
sellermenu=raw_input("In what area would you like to buy?"\n (1)Stocks\n (2) Bonds\ (3) Nevermind\n)
if playermenumain=="3":
break
#main menu loop: no matter what is selected, player is directed back to main menu until option 3 (end turn) is selected:
while playermenumain=="1" or playermenumain=="2":
playermenumain=raw_input("What would you like to do?\n (1) Buy\n (2)Sell\n (3)Hold and end turn ")
continue
這是怎麼回事的參數'raw_input'?你顯示的內容看起來不像有效的語法。 –