investment = 10000
for i in range(20):
yearly_interest = investment *.05
investment = investment * yearly_interest
investment = round(investment, 2)
嗨,我不太确定这个循环如何给出所需的答案。如果有人可以帮助我理解为什么它没有提出答案以及可以怎么做。在Mauch的书中,他们解释说这是循环之一,但它没有返回所需的值(“ 20年后的值将是多少”)
答案 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)