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 formulacapital * (1 + rate / 100) ** yearsand the default valuesrate=5.0andyears=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 showFinal capital: xwith two decimals.
1000
-
2
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