我正在尝试创建带有子菜单的主菜单。我想这样做,无论用户从主菜单到子菜单选择什么顺序,他们最终都会被引导回主菜单——也就是说,直到他们选择最后一个选项(3.按住并结束转弯) .
这就是我卡住的地方。现在,用户只能通过菜单序列一次。我如何使它成为一个重复循环?
#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