Lab07 题解 (UCB CS61A@2021 Fall)
Accounts
Q2: Retirement
Add a
time_to_retire
method to theAccount
class. This method takes in anamount
and returns how many years the holder would need to wait in order for the currentbalance
to grow to at leastamount
, assuming that the bank addsbalance
times theinterest
rate to the total balance at the end of every year.
问题描述如下: 每一年你的 balance
都会有利息, 问你哪一年你达到了 amount
可以退休了, 用代码模拟这个过程即可