Price Rules That Stack

Python for AIMedium+10 XP+10

Price Rules That Stack

A shop's price rules stack on top of each other.

The starter code gives you Product(price), where final_price() returns price. Don't change it.

  • TaxedProduct is a child of Product. Its final_price() takes the parent's final price and adds 20% tax (multiply by 1.2), rounded to 2 decimal places.
  • SaleProduct is a child of TaxedProduct. Its final_price() takes the taxed price and subtracts 5, never going below 0. Round it to 2 decimal places.

Use super() so that if the tax rule changes later, sale prices change with it.

Examples

TaxedProduct(10).final_price()
returns 12.0
SaleProduct(10).final_price()
returns 7.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