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 to write this program in Python. Write a program that displays a temperature conversion...
I need to write this program in Python. Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The tabular format of the result should include rows for all temperatures between 70 and 270 degrees Celsius that are multiples of 10 degrees Celsius (check the sample below). Include appropriate headings on your columns. The formula for converting between degrees Celsius and degrees Fahrenheit is as follow F=(9/5C) +32 Celsius Fahrenheit 70 158 80 176 90...
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 Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
Write a Python program that simulates a restaurant ordering system where it stores multiple orders of...
Write a Python program that simulates a restaurant ordering system where it stores multiple orders of a dish and the price for each order stored into a list. The program will then print the receipt which includes list of orders and their price along with the subtotal before tax, the tax amount, and the final total. Also include tip suggestions for 10%, 15% and 20%. Use the format specifiers to make the price line up and the tip only 2...
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...
Using Python, Assignment Write a program that plays a game of craps. The program should allow...
Using Python, Assignment Write a program that plays a game of craps. The program should allow the player to make a wager before each “turn”. Before each turn, allow the user to either place a bet or exit the game. After each turn display the player’s current balance. Specifics Each player will start with $500.00. Initially, and after each turn give the user the option of betting or leaving the program. Implement this any way you wish, but make it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT