繁体   English   中英

我正在尝试编写一个“机器人”服务员程序,但我似乎找不到我出错的地方

[英]I am trying to program a "robot" waiter program but I can't seem to find where I went wrong

我的程序有错误和错误需要修复。 这是关于一个“机器人”,它是餐厅的服务员。 我还是个初学者。

我尝试查看我的程序中的错误,并尝试缩进和删除程序的不同部分以尝试使其正常工作。 我也尝试与操作员混在一起,但似乎没有任何效果。

import sys, time
total = 0
menu = ["0 - Swedish Meatballs - 5$", "1 - Japanese Sushi - 7$", "2 - Indian Rice - 9$", "3 - Quit"]
price = [5,7,9,0]
print("Hello welcome to the restaurant! I am your robotic waiter")
action = int(input("What would you like to do? \n 1. Look at the menu \n 2. Order \n 3. Take more time \n 4. Ask for the total \n 5. Exit \n Please enter a number here: "))
while action != 5:
        if action == 1:
                print(menu)
                action = int(input("What would you like to do? \n 1. Look at the menu \n 2. Order \n 3. Take more time \n 4. Ask for the total \n 5. Exit \n Please enter a number here: "))
        elif action == 2:
                print(menu)
                food = int(input("What would you like? "))
                while food != 3:
                        priceoffood = price[food]
                        total = total + priceoffood
                        if food != 3:
                                more = input("More things? Reply with y or n: ")
                                if more == "y":
                                        print(menu)
                                        food = int(input("What would you like? "))
                                        if priceoffood != 3:
                                                print(food)
                                                print(price[food])
                                                priceoffood = price[food]
                                                total = total + priceoffood
                        else:
                                break
        elif action == 3:
                time = int(input("How many minutes more do you need?  "))
                while int(time) > 30:
                        print ("Isn't that too long? ")
                        time = input("How many minutes more do you need?  ")
                print("Okay, ill be back when your " + str(time) + " minutes are over!")
                time.sleep(time*60)
        elif action == 4:
                print("Your total is: " + str(total))
quit()

我希望菜单功能能够像预期的那样工作。

您导入了time ,但也将其用作变量。 将您的变量更改为时间以外的其他内容。 例如:

timer = int(input("How many minutes more do you need?  "))
while int(timer) > 30:
    print ("Isn't that too long? ")
    timer = input("How many minutes more do you need?  ")
print("Okay, ill be back when your " + str(timer) + " minutes are over!")
time.sleep(timer*60)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM