Advanced functions and decorators · 9 / 15 Exercise Easy

Final price with default values

Objective

Create a Python program with a function that computes a final price and has optional parameters with a default value.

Instructions

  • Define def final_price(price, tax=21, discount=0). First apply the discount (percentage) and then the tax (percentage): price * (1 - discount / 100) * (1 + tax / 100).
  • Read a line with 1, 2 or 3 numbers separated by spaces: the price, and optionally the tax and the discount, in that order.
  • Call the function only with the values you have received, so that the missing ones use their default value.
  • Show Final price: P with 2 decimals.
Input
100
Output
Final price: 121.00

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise