Mauch回路测试

2024-10-03 17:17:04 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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


Tags: 答案inforrangeroundinterestyearlyinvestment
1条回答
网友
1楼 · 发布于 2024-10-03 17:17:04

yearly_interest应该添加到investment中,而不是将investment乘以它

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

相关问题 更多 >