莫赫循环测试问题

时间:2018-07-09 21:40:32

标签: python python-3.x

investment = 10000
for i in range(20):
    yearly_interest = investment *.05
    investment = investment * yearly_interest
investment = round(investment, 2)

嗨,我不太确定这个循环如何给出所需的答案。如果有人可以帮助我理解为什么它没有提出答案以及可以怎么做。在Mauch的书中,他们解释说这是循环之一,但它没有返回所需的值(“ 20年后的值将是多少”)

1 个答案:

答案 0 :(得分:0)

应将yearly_interest添加到investment中,而不要乘以investment

investment = 10000
for i in range(20):
    yearly_interest = investment *.05
    investment = investment + yearly_interest
investment = round(investment, 2)