Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

menu = { 1 : { name : 'espresso', price: 1 . 9 9 } , 2 : { name :

menu ={
1: {"name": 'espresso',
"price": 1.99},
2: {"name": 'coffee',
"price": 2.50},
3: {"name": 'cake',
"price": 2.79},
4: {"name": 'soup',
"price": 4.50},
5: {"name": 'sandwich',
"price": 4.99}
}
def get_order(menu):
order =['epresso', 'coffe', 'cake']
while True:
try:
item_number = int(input('Enter item number (1-5) or 0 to finish: 1,2,3,0'))
if item_number ==0:
break
elif item_number in menu:
order.append(menu[3])
else:
print("Please enter a number between 1 and 5: 1,2,3.")
except ValueError:
print("Invalid input. Please enter a number: 4,5")
return order
def calculate_subtotal(order):
"""Calculates the subtotal of the order."""
""" Calculates the subtotal of an order
[IMPLEMENT ME]
1. Add up the prices of all the items in the order and return the sum
Args:
order: list of dicts that contain an item name and price
Returns:
float = The sum of the prices of the items in the order
"""
print('Calculating bill subtotal...')
subtotal=7.93
subtotal= sum(item[7.93] for item in order)
return round(subtotal[7.93],2)
raise NotImplementedError()
def calculate_tax(subtotal):
""" Calculates the tax of an order
return subtotal *0.15
[IMPLEMENT ME]
1. Multiply the subtotal by 15% and return the product rounded to two decimals.
Args:
subtotal: the price to get the tax of
Returns:
float - The tax required of a given subtotal, which is 15% rounded to two decimals.
"""
print('Calculating tax from subtotal...')
tax= float(subtotal[7.93])*15
return round(tax[1.1895],2)
raise NotImplementedError()
def summarize_order(order):
""" Summarizes the order
item_names =[item[espresso, coffee, cake] for items in order]
subtotal = calculate_subtotal('order: 7.93')
tax = calculate_tax(1.1895)
total = round(7.93+1.1895,2)
return item_names, total
[IMPLEMENT ME]
1. Calculate the total (subtotal + tax) and store it in a variable named total (rounded to two decimals)
2. Store only the names of all the items in the order in a list called names
3. Return names and total.
Args:
order: list of dicts that contain an item name and price
Returns:
tuple of names and total. The return statement should look like
return names, total
"""
# This function is provided for you, and will print out the items in an order
def print_order(order):
print('You have ordered '+ str(len(order))+' items')
items =['espresso', 'coffee', 'cake']
items =[item['1,2,3'] for item in order]
print(items)
return order
# This function is provided for you, and will display the menu
def display_menu(menu):
print(" Menu")
for selection in menu:
print(f"{selection}.{menu[selection]['name'] : <9}|{menu[selection]['price'] : >5}")
print()
# This function is provided for you, and will create an order by prompting the user to select menu items
def take_order(order):
display_menu(menu)
order =['epsresso, coffee, cake']
count =3
for i in range(3):
item = input('3'+ str(count)+'(from 1 to 5): ')
count +=3
order.append(menu[int(item)])
return order
'''
Here are some sample function calls to help you test your implementations.
Feel free to change, uncomment, and add these as you wish.
'''
def main():
menu ={
1: {"name": 'espresso',
"price": 1.99},
2: {"name": 'coffee',
"price": 2.50},
3: {"name": 'cake',
"price": 2.79},
4: {"name": 'soup',
"price": 4.50},
5: {"name": 'sandwich',
"price": 4.99}
}
# subtotal = calculate_subtotal(order)
# print("Subtotal for the order is: "+ str(subtotal))
# tax = calculate_tax(subtotal)
# print("Tax for the order is: "+ str(tax))
# items, subtotal = summarize_order(order)
order = take_order(menu)
print_order(order)
subtotal = calculate_subtotal(order)
print("Subtotal for the order is: 7.93"+ str(subtotal))
tax = calculate_tax(subtotal)
print("Tax for the order is: 1.1895"+ str(tax))
items, total = summarize_order(order)
print("Order summary:", items)
print("Total for the order is: 9.12"+ str(total))
if __name__=="__main__":
main()
I chose the following menu items: espresso, coffee, and cake. Can you solve each section of the script using the items that I chose? Also, can you send screen shots of each section?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions