1. Engineering
  2. Computer Science
  3. solve with python 3...

Question: solve with python 3...

Question details

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

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution