Question

In: Computer Science

I need to write a program in python for a restaurant. The program should let the...

I need to write a program in python for a restaurant. The program should let the user enter a meal number, then it should display the meal name, meal price, and meal calories. Also, needs the appropriate output if the user enters an invalid meal number. I am supposed to use a dictionary, but my problem is it keeps giving me an error and telling me my menu is not defined. Not sure what I am doing wrong.


print ("Welcome to INN N OUT, what would you like to order today?")
print("------Menu------")
print("Double Double - 1")
print("Cheeseburger - 2")
print("Hamburger - 3")

def Menu():
menu = {

1 : {'name' : 'Double Double','price' : 3.45,'calories' : 670},

2 : {'name' : 'Cheeseburger','price' : 2.40,'calories' : 480},

3: {'name' : 'Hamburger','price' : 2.10,'calories': 310}}

x = int(input("Make a selection: "))

if x >= 1 and x <= 3:
print("You ordered a " + menu[x]['name'] + ". That is " + menu[x]['calories'] + ". Your total will be $" + menu[x]['price'])

else:
print("Invalid entry.")

Menu()

Solutions

Expert Solution

I hope the error that you were getting was due to the proper indentation in Python. Please note that Python strictly identifies and executes the code based on the indentation. I have indented it properly. Please see the code below. Also please refer to the screenshot for guidance on the indentation.

Another thing that I have noticed is when you are printing the price and calories in the output. It was giving an error when trying to concatenate int and string. An explicit conversion to string is required when concatenating int with string. I have modified that also.

print ("Welcome to INN N OUT, what would you like to order today?")
print("------Menu------")
print("Double Double - 1")
print("Cheeseburger - 2")
print("Hamburger - 3")

def Menu():
    menu = {
    1 : {'name' : 'Double Double','price' : 3.45,'calories' : 670},
    2 : {'name' : 'Cheeseburger','price' : 2.40,'calories' : 480},
    3 : {'name' : 'Hamburger','price' : 2.10,'calories': 310}}
    x = int(input("Make a selection: "))
    print(x)

    if x >= 1 and x <= 3:
        #When concatenating string and int, use str() function to convert int to string and then concatenate.
        print("You ordered a " + menu[x]['name'] + ". That is " + str(menu[x]['calories']) + " calories. Your total will be $" + str(menu[x]['price']))
    else:
        print("Invalid entry.")

Menu()

The screenshots of the code and output are provided below.


Related Solutions

I need a python program and a flowchart please!! Problem #1:    How much should I...
I need a python program and a flowchart please!! Problem #1:    How much should I study outside of class?                         Issue: Your fellow students need help. This is their first year in college and they need to determine how many hours they need to study to get good grades. Study Hours Per Week Per Class                    Grade 15                                                           A 12                                                           B 9                                                             C 6                                                             D 0                                                             F Project Specifications: The user enters their full name and the number of...
I need to write an interpreter for arithmetic expressions in Python. This program receives an input...
I need to write an interpreter for arithmetic expressions in Python. This program receives an input string with an arithmetic expression and does: 1. prints a ">>>" as if it was a terminal 2. lets us allocate a variable to a a numeric value (as "a = 3") then it stores {'a':3} to a dictionary memory 3. whenever it receives an expression or input, transform it to postfix notation and print it (even when allocating variables) 4. it is able...
I need to write PYTHON program which is like a guessing game using randint function which...
I need to write PYTHON program which is like a guessing game using randint function which is already done, the user has to guess a number between 1 and 1000 and the game musn't end until you guess the number, if you input a smaller number you must get hints, the same goes if your input is bigger than the wining number , also you must get notified if you repeat a number (example, you pick 1 and in the...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
I need to write a response to how I should I should plan to build financial...
I need to write a response to how I should I should plan to build financial security starting with a job right out of college. I need to include everything seen below. If you can answer in bullet points for each question or a paragraph answering the short parts. Below is the guide Include – Why, What, When, and How a. Financial Goals: Near-term: 1 to 2 yrs; Intermediate-term: 3 – 5 yrs; Long-term: 6 – 15 yrs b. Savings...
hello, I need a python program for a drone to follow keyboard commands - Create a...
hello, I need a python program for a drone to follow keyboard commands - Create a simple single obstacle environment and program the drone to navigate through it - Create a more advanced obstacle environment (3+ obstacles) and program the drone to navigate through it
in python, sorry i thought i wrote it Write an interactive program that repeatedly asks the...
in python, sorry i thought i wrote it Write an interactive program that repeatedly asks the user to input a number until”Enter” is hit. Your program should create a file named “numbers.txt” where all the numbersare written one below the other, and the last line should display the sum of all the input, afterthe string “The sum of your numbers is ”.For example, if the user inputs 3, 5, 7, 10, -3, 5.2, then the file “numbers.txt” should contain: 3...
Need this program in python. The data must be taken from user as input. Write a...
Need this program in python. The data must be taken from user as input. Write a program that prompts the user to select either Miles-to-Kilometers or Kilometers-to-Miles, then asks the user to enter the distance they wish to convert. The conversion formula is: Miles = Kilometers X 0.6214 Kilometers = Miles / 0.6214 Write two functions that each accept a distance as an argument, one that converts from Miles-to-Kilometers and another that converts from Kilometers-to-Miles The conversion MUST be done...
PYTHON Let n denote an integer entered by the user. Write a program to print n...
PYTHON Let n denote an integer entered by the user. Write a program to print n multiples of 5 in the descending order, with the last number being 5. Print the average of those n multiples
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT