我是一个初级程序员,有一个关于根据以下公式计算未来投资价值的问题: futureInvestmentValue=投资金额*(1+月利率)月数 ... ofc numberOfMonths值是一个指数。 到目前为止,我已经创建了这个程序,但是在运行程序时似乎收到了不正确的答案
#Question 2
investmentAmount = float(input("Enter investment amount: "))
annualInterestRate = float(input("Enter annual interest rate: "))
monthlyInterestRate = ((annualInterestRate)/10)/12
numberOfYears = eval(input("Enter number of years: "))
numberOfMonths = numberOfYears * 12
futureInvestmentValue = investmentAmount * (1 + monthlyInterestRate) **\
numberOfMonths
print("Accumulated value is", futureInvestmentValue)
我需要做些什么才能使这件事正常工作,任何帮助都将不胜感激谢谢
错误在:
我认为有两个错误。第一个是利率被10除,而它应该被除以100。现在,如果输入2,它将被视为20%的利息,因为
2/10
=.2
。在第二个错误是}假设复合利率。应该是的
monthlyInterestRate
假设一个固定利率,而{monthlyInterestRate = (1 + (annualInterestRate/100))**(.1/1.2)
。在例如(使用/12):
^{pr2}$输出:
月利率复利不等于一年的年利率。这是因为在一个例子中你除以12,下一个例子,你提高到12的幂,这是不相等的。在
示例(使用**1/12)
你可以这样做:
annualInterestRate
应除以12得到monthlyInterestRate
。在正确的最终公式应该是
相关问题 更多 >
编程相关推荐