Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The following code was written by you guys earlier but it fails when I pass the below signature. cost _ calculator ( [ ] ,
The following code was written by you guys earlier but it fails when I pass the below signature.
costcalculatorham "anchovy" drinkstub "tub" coupon
costcalculatorpepperoni "pepperoni" wings drinkssmall
def costcalculatorpizzas drinks wings coupon:
# Define prices for each item
basepizzaprice
toppingsprices
"pepperoni":
"mushroom":
"olive":
"anchovy":
"ham":
drinksprices
"small":
"medium":
"large":
"tub":
wingsprices
:
:
:
:
# Calculate the cost for pizzas
pizzacost sumbasepizzaprice sumtoppingsprices.gettopping for topping in pizza for pizza in pizzas
# Calculate the cost for drinks
drinkcost sumdrinksprices.getsize for size in drinks
# Calculate the cost for wings
wingcost sumwingsprices.getquantity for quantity in wings
# Calculate total cost before coupon
totalcostbeforecoupon pizzacost drinkcost wingcost
# Apply coupon discount
discount totalcostbeforecoupon coupon # Coupon value is assumed to be a percentage
totalcostafterdiscount totalcostbeforecoupon discount
# Apply tax
tax totalcostafterdiscount # Tax rate is
finalcost totalcostafterdiscount tax
# Round the final cost to decimal places
finalcostrounded roundfinalcost
return finalcostrounded
# Example usage:
printcostcalculatorpizzasham "anchovy" drinkstub "tub" wings coupon
printcostcalculatordrinkssmall
printcostcalculatorpizzaspepperoni "pepperoni" wings drinkssmall
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started