Answered step by step
Verified Expert Solution
Link Copied!

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.
cost_calculator([],["ham", "anchovy"], drinks=["tub", "tub"], coupon=0.1)
cost_calculator([],[],["pepperoni", "pepperoni"], wings=[10,20], drinks=["small"])
=============================================================
def cost_calculator(pizzas=[], drinks=[], wings=[], coupon=0):
# Define prices for each item
base_pizza_price =13.00
toppings_prices ={
"pepperoni": 1.00,
"mushroom": 0.50,
"olive": 0.50,
"anchovy": 2.00,
"ham": 1.50
}
drinks_prices ={
"small": 2.00,
"medium": 3.00,
"large": 3.50,
"tub": 3.75
}
wings_prices ={
10: 5.00,
20: 9.00,
40: 17.50,
100: 48.00
}
# Calculate the cost for pizzas
pizza_cost = sum(base_pizza_price + sum(toppings_prices.get(topping,0) for topping in pizza) for pizza in pizzas)
# Calculate the cost for drinks
drink_cost = sum(drinks_prices.get(size,0) for size in drinks)
# Calculate the cost for wings
wing_cost = sum(wings_prices.get(quantity,0) for quantity in wings)
# Calculate total cost before coupon
total_cost_before_coupon = pizza_cost + drink_cost + wing_cost
# Apply coupon discount
discount = total_cost_before_coupon *(coupon /100) # Coupon value is assumed to be a percentage
total_cost_after_discount = total_cost_before_coupon - discount
# Apply tax
tax = total_cost_after_discount *0.0625 # Tax rate is 6.25%
final_cost = total_cost_after_discount + tax
# Round the final cost to 2 decimal places
final_cost_rounded = round(final_cost,2)
return final_cost_rounded
# Example usage:
print(cost_calculator(pizzas=[[],["ham", "anchovy"]], drinks=["tub", "tub"], wings=[10,20], coupon=10))
print(cost_calculator(drinks=["small"]))
print(cost_calculator(pizzas=[[],[],["pepperoni", "pepperoni"]], wings=[10,20], drinks=["small"]))
=============================================================

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

Students also viewed these Databases questions

Question

When is it appropriate to use a root cause analysis

Answered: 1 week ago

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago