简体   繁体   English

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

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

My program has errors and bugs that I need to fix.我的程序有错误和错误需要修复。 It's about a "robot" that is a waiter in a restaurant.这是关于一个“机器人”,它是餐厅的服务员。 I am still a beginner.我还是个初学者。

I tried looking through my program for the bugs and tried indenting and dedenting different parts of my program to try and get it working.我尝试查看我的程序中的错误,并尝试缩进和删除程序的不同部分以尝试使其正常工作。 I als o tried messing around with the operators but nothing seems to work.我也尝试与操作员混在一起,但似乎没有任何效果。

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

I would like the menu functions to be working just like how they are expected to be.我希望菜单功能能够像预期的那样工作。

You imported time , but also used it as a variable.您导入了time ,但也将其用作变量。 Change your variable to something other than time.将您的变量更改为时间以外的其他内容。 For example:例如:

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.

相关问题 试图找到我在python代码中出错的地方 - Trying to find where I went wrong in my python code 我正在尝试为我重新排序单词的程序,但是它似乎没有用 - I am trying to make a program to reorderwords for me but it doesnt seem to be working 我正在尝试解决黑客等级问题。 我还是一个初学者,我不知道Python 3出了什么问题 - I am trying to solve the hacker rank problem. I am still a beginner and I don't know where I went wrong with Python 3 我正在尝试使用 selenium 加载等待列表并单击按钮,但我似乎找不到该元素 - I am trying to use selenium to load a waiting list and click the button, but I can't seem to find the element 我试图了解类和函数,但似乎无法弄清楚我的代码出了什么问题 - I am trying to understand class and function and can't seem to figure out what is wrong with my code 我似乎无法摆脱这个程序在 python 上的循环 - I can't seem to get out of the loop on this program on python Python 不断返回断言错误,但我不知道哪里出错了 - Python keeps returning an assertion error but I can’t tell where I went wrong 我不明白为什么我不能让 python 中的 readline function 在这个程序中工作。 我究竟做错了什么? - I don't understand why i can't get readline function in python to work in this program. What am I doing wrong? 我正在尝试使用记事本++启动一个简单的计算器程序,我做错了什么? - I am trying to start a simple calculator program using notepad++, what am I doing wrong? 我是 python 新手,我找不到为什么这个程序不起作用? - I am new to python and i can't find why this program is not working?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM