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

时间:2019-04-20 18:24:01

标签: python python-3.x

我的程序存在我需要修复的错误和错误。这是关于“机器人”的,它是餐厅的服务生。我仍然是初学者。

我尝试遍历程序中的错误,并尝试使程序的不同部分缩进和缩进,以使其正常运行。我也尝试过与操作员打乱,但似乎没有任何作用。

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

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

1 个答案:

答案 0 :(得分:1)

您导入了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)