我希望结果显示每年增加利息后的总金额,但它只会增加年份而不是金额。为什么呢?
while True:
try:
investment = float(input('How much to invest : '))
interest = float(input('Interest rate : '))
break
except ValueError:
"Please enter a valid number"
for year in range(10):
money = investment + (investment * interest)
print("Total money in year {} : {}".format((year+1), money))
答案 0 :(得分:2)
听起来你需要产生兴趣:
for year in range(10):
investment += (investment * interest)
print("Total money in year {} : {}".format((year + 1), investment))
答案 1 :(得分:1)
逻辑错误。您的investment
变量不会在循环中的每一轮分配。