【问题标题】:How do i make this program re-run from the beginning after the input "yes"输入“是”后如何使该程序从头开始重新运行
【发布时间】:2017-11-04 19:36:16
【问题描述】:
print("1, Rice")
print("2, Amala")
print("3, Semolina")
print("4, Chicken")


Mainchoice=int(input("Select a number of choice:"))
if(Mainchoice==1):
    print("1, Rice and Beans with meat/fish.")
    print("2, Jollof Rice and chicken wings.")
    print("3, Fried Rice and Beef.")
    Rice=int(input("Select a Rice of choice:"))
    if(Rice==1):

        print("You selected Rice and Beans with meat/fish.")

    elif(Rice==2):

        print("You selected Jollof Rice and Chicken wings.")
    elif(Rice==3):

        print("You selected Fried Rice and Beef.")
    else:
        print("Please select a valid number from the list above.")

elif(Mainchoice==2):
    print("1, Amala and ewedu with beef.")
    print("2, Amala and efo riro with assorted meat.")
    print("3, Amala and egusi soup with meat.")
    Amala=int(input("Select an Amala of choice:"))
    if(Amala==1):
        print("You selected Amala and ewedu with beef.")
    elif(Amala==2):
        print("You selected Amala and efo riro with assorted meat.")
    elif(Amala==3):
        print("You selected Amala and egusi with meat.")
    else:
        print("Please select a valid number from the list.")
elif(Mainchoice==3):
    print("1, Semolina and Ogbono soup with meat.")
    print("2, Semolina and efo riro with beef.")
    print("3, Semolina with egusi soup and draw.")
    Semolina=int(input("Select Semolina of choice:"))
    if(Semolina==1):
        print("You selected Semolina and Ogbono soup with meat.")
    elif(Semolina==2):
        print("You selscted Semolina and efo riro with beef.")
    elif(Semolina==3):
        print("You selected Semolina with egusi soup and draw.")
    else:
        print("Plese select a valid command from the list.")
elif(Mainchoice==4):
    print("1, Grilled Chicken breast and laps.")
    print("2, Roasted Full Chicken with tomato ketchup sauce.") 
    print("3, Chicken Barbeque.")
    Chicken=int(input("Select a Chicken of choice:"))
    if(Chicken==1):
        print("You selected Grilled Chicken braest and laps.")
    elif(Chicken==2):
        print("You selected Roasted Full Chicken with tomato ketchup sauce.")
    elif(Chicken==3):
        print("You selected Chicken Barbeque.")
    else:
        print("Please select a valid command from the list.")
else:
    print("Please select a valid number.")

def Canteen():
    return str (Mainchoice)



def Loop():
    r=(input("Would you like to re-select the options again?:"))
    if (r=="yes"):
       Loop()
    if (r=="No"):
       print("Goodbye")
Loop()

该代码可帮助用户在食堂预订食物。 它在用户输入选定的食物项后显示食物项。请在用户输入“是”后添加什么python代码行以使程序从头开始重新运行。 我已经能够找出“否”选项。 任何解决方案将不胜感激。 谢谢。

【问题讨论】:

  • 你知道如何使用循环吗?通常,您会为这样的事情使用 while 循环。

标签: python-3.3


【解决方案1】:

只需编辑最后一行。

if __name__ == "__main__":
    while True:
        Loop()

如果您需要从这里退出,请使用 Control + C

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-09
    • 1970-01-01
    • 2013-07-17
    • 1970-01-01
    相关资源
    最近更新 更多