Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Solve with python 3 An online store requires a Python function to calculate the price of orders. The function should be called calculate_price and take
Solve with python 3
An online store requires a Python function to calculate the price of orders. The function should be called calculate_price and take the following two arguments (in order): price: A dictionary mapping the name of each item sold by the store to the price of the item (in dollars) .order A dictionary mapping the name of each item a customer wishes to buy to the quantity of that item they wish to purchase The function should iterate over each item in the order and add the price to buy the desired quantity of that item to the total cost of the order. If any item in the order does not have a corresponding price, your function should raise a KeyError Once the cost of each item in the order has been calculated, the function should test to see if the overall cost for all items is greater than $100, if it is, a 10% discount should be applied to the overall cost. Otherwise, if the order is greater than $50, a 5% discount should be applied The overall cost of the order (after any applicable discounts) should then be returned by the function. Write a function to meet these requirements 1 def calculate_price(price, order): # TODO: Implement this pass Tests 5 price 'book' 10.0, magazine: 5.5, "newspaper': 2.0
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