Question: menu = { 1 : { name : 'espresso', price: 1 . 9 9 } , 2 : { name :
menu
: name: 'espresso',
"price":
: name: 'coffee',
"price":
: name: 'cake',
"price":
: name: 'soup',
"price":
: name: 'sandwich',
"price":
def getorder:
order epresso 'coffe', 'cake'
while True:
try:
itemnumber intinput
if itemnumber :
break
elif itemnumber in menu:
order.appendmenu
else:
print
except ValueError:
printInvalid input. Please enter a number."
return order
def calculatesubtotalorder:
Calculates the subtotal of the order."""
Calculates the subtotal of an order
IMPLEMENT ME
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
printCalculating bill subtotal...
subtotal
subtotal floatitem
return roundsubtotal
raise NotImplementedError
def calculatetaxsubtotal:
Calculates the tax of an order
return subtotal
IMPLEMENT ME
Multiply the subtotal by 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 rounded to two decimals.
printCalculating tax from subtotal...
tax floatsubtotal
return roundtax
raise NotImplementedError
def summarizeorderorder:
Summarizes the order
itemnames itemespresso 'coffee', 'cake' for items in order
subtotal calculatesubtotalorder
tax calculatetaxsubtotal
total subtotal tax
return itemnames, total
IMPLEMENT ME
Calculate the total subtotal tax and store it in a variable named total rounded to two decimals
Store only the names of all the items in the order in a list called names
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
printorderorder
subtotal calculatesubtotal
tax calculatetaxsubtotal
total round floatsubtotal tax
names itemname for item in order
return names, total
raise NotImplementedError
# This function is provided for you, and will print out the items in an order
def printorderorder:
printYou have ordered strlenorder items'
items espresso 'coffee', 'cake'
items item for item in order
printitems
return order
# This function is provided for you, and will display the menu
def displaymenu:
print Menu
for selection in menu:
printfselectionmenuselectionname : menuselectionprice :
print
# This function is provided for you, and will create an order by prompting the user to select menu items
def takeorderorder:
displaymenu
order epsresso coffee, cake'
count
for i in range:
item input strcountfrom to :
count
order.appendmenuintitem
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:
order takeorderepresso coffee, cake'
printorderorder
# subtotal calculatesubtotalorder
# printSubtotal for the order is: strsubtotal
# tax calculatetaxsubtotal
# printTax for the order is: strtax
# items, subtotal summarizeorderorder
if namemain:
main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
