《python语言程序设计》第6章第7题财务应用程序:计算未来投资,编写函数计算制定年数以给定利率
记住这里增加循环应该是以年为单位。但是添加的数是月为单位
此处需留意其实点不是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)
原文地址:https://blog.csdn.net/m0_37228426/article/details/140654477
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!