Functions · 25 / 27 Exercise Easy

Interest with default values

Objective

A parameter can have a default value: if that argument is not given when calling the function, the default is used. Arguments can be given by position or by name.

Instructions

  • Define compound_interest(capital, rate=5.0, years=1) with the formula capital * (1 + rate / 100) ** years and the default values rate=5.0 and years=1.
  • Read the capital (decimal), then the rate and then the years. Each of the last two may be -: in that case that argument is not given and the default value is used.
  • Call the function with the arguments that were given (use the name years= if you only give the years) and show Final capital: x with two decimals.
Input
1000
-
2
Output
Final capital: 1102.50

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

Start exercise