Update the Amount
00:00
Currently, the amount stays the same for every step of the for
loop. So that’s what you will tackle next. Before your print()
function calls, add in a new line where you update the amount
variable with every for
loop step.
00:15
So amount = amount
—that’s the current value that amount
has—multiplied by the rate
, but the rate
is 0.05
, for example.
00:25
So you need to put this in parentheses and say (1 + rate)
because you want to increase the amount. So now it says amount = amount * (1 + rate)
.
00:41
Then you can adjust the f-string and the function call below to show the amount
in the string.
00:48
You can also remove the print()
call with the amount
and the rate
to just show year
, and then the year number, and then the amount
.
00:56
And when you run the module now, then you can see that the amount
increases with each year exactly like you want it to increase. But as you can see, it’s not rounded to two decimal places just yet.
01:10 But for now, it’s good news that your function generally works, but it doesn’t display entirely what you want to display yet.
Become a Member to join the conversation.
reapyt on May 3, 2024
I don’t understand the way amount is updated in the invest function provided in this video. Why do we add 1 to rate?
I came up with this solution:
And I also understand the solution given for the same exercise in the Python Basics book:
Any help would be appreciated. Thank you in advance.