记住这里增加循环应该是以年为单位。但是添加的数是月为单位
此处需留意其实点不是1,1代表1年,这里月所以其实是12,这里的单位是月,而不是年。
python for i in range(12,monthNum+12,12)
如果你把12都换成1呢???可以试试结果
python for i in range(1,monthNum,12)
下面是正确的
investMent_t = eval(input("Enter investment amount: "))
annualInterest_t = eval(input("Enter annual interest rate: "))
years_t = eval(input("Enter number of years: "))
def futureInvestmentValue(investmentAmount, monthlyInterestRate, years):
monthAnnual = monthlyInterestRate / 1200
monthNum = years * 12
# 此处需留意其实点不是1,1代表1年,这里月所以其实是12,这里的单位是月,而不是年。
for i in range(12, monthNum+12, 12):
a = round(investmentAmount * pow(1 + monthAnnual, i), 2)
print("{:}year Accumulated value is {:.2f}".format(i, a))
futureInvestmentValue(investMent_t, annualInterest_t, years_t)