Members Save Ten Percent

Data with PythonMedium+10 XP+10

Members Save Ten Percent

A bookshop works out the total for each order as price × quantity. Members get 10% off, but only on orders whose total is £50 or more.

Task: write order_totals(orders) that returns the amount each customer pays.

  • orders is a list of dictionaries, each with customer, price, qty and member (True or False).
  • Add a total column: price × quantity.
  • For members whose total is 50 or more, change the total to 90% of itself. A total of exactly 50 counts.
  • Return the total column as a list in the original order, with every value rounded to 2 decimal places.

Examples

orders = [{"customer": "Ana", "price": 12.5, "qty": 4, "member": True}, {"customer": "Ben", "price": 30.0, "qty": 2, "member": False}, {"customer": "Cara", "price": 9.99, "qty": 3, "member": True}, {"customer": "Dev", "price": 18.0, "qty": 5, "member": True}]
returns [45.0, 60.0, 29.97, 81.0]
orders = [{"customer": "Eli", "price": 7.0, "qty": 7, "member": True}, {"customer": "Fay", "price": 25.0, "qty": 4, "member": True}]
returns [49.0, 90.0]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run