如何在输入后从头开始重新运行该程序"是"

时间:2017-11-04 19:36:16

标签: python-3.3

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()

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

1 个答案:

答案 0 :(得分:0)

只需编辑你的最后一行。

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

如果您需要从此处退出,请使用Control + C