如何让Python复利计算器给出正确答案?

如何让Python复利计算器给出正确答案?,python,calculator,Python,Calculator,我遇到了我的复利计算器的问题,当你输入本金、复利(年、月等)、利率(0.03等)和年数时,它给出了错误的计算 因此,从前面的代码中,我删除了p=10000,n=12,r=0.08,因为当您输入不同的数字时,它会给出一个很大的数字。我希望它能用输入的数字来计算,但事实并非如此 # User must input principal, Compound rate, annual rate, and years. P = int(input("Enter starting principl

我遇到了我的复利计算器的问题,当你输入本金、复利(年、月等)、利率(0.03等)和年数时,它给出了错误的计算

因此,从前面的代码中,我删除了
p=10000,n=12,r=0.08
,因为当您输入不同的数字时,它会给出一个很大的数字。我希望它能用输入的数字来计算,但事实并非如此

# User must input principal, Compound rate, annual rate, and years.
P = int(input("Enter starting principle please. "))
n = int(input("Enter Compound intrest rate.(daily, monthly, quarterly, half-year, yearly) "))
r = float(input("Enter annual interest amount. (decimal) "))
t = int(input("Enter the amount of years. "))

final = P * (((1 + (r/n)) ** (n*t)))
#displays the final amount after number of years.
print ("The final amount after", t, "years is", final)
# At the moment it is displaying a very random number.

Enter starting principle please. 1000
Enter Compound intrest rate.(daily, monthly, quarterly, half-year, yearly) 1
Enter annual interest amount. (decimal) 0.01
Enter the amount of years. 1
The final amount after 1 years is 1010.0

最终金额应为
1000.10
。不知道发生了什么事。尝试查看是否有方法使
P,n,r
等于用户输入的数量,从而得到正确的最终答案。

如果您输入的是百分比,您应该在代码中注意这一点

final = P * (((1 + (r/(100.0 * n))) ** (n*t)))

如果您输入的是百分比利息,您应该在代码中注意这一点

final = P * (((1 + (r/(100.0 * n))) ** (n*t)))
基于此: 复利公式 FV=P(1+r/n)^Yn, 其中P为起始本金,r为年利率,Y为投资年数,n为每年的复利期数。FV是未来价值,表示本金在Y年后增长到的金额

P = int(input("Enter starting principle please. "))
n = int(input("Enter number of compounding periods per year. "))
r = float(input("Enter annual interest rate. e.g. 15 for 15% "))
y = int(input("Enter the amount of years. "))

FV = P * (((1 + ((r/100.0)/n)) ** (n*y)))

print ("The final amount after", y, "years is", FV)
基于此: 复利公式 FV=P(1+r/n)^Yn, 其中P为起始本金,r为年利率,Y为投资年数,n为每年的复利期数。FV是未来价值,表示本金在Y年后增长到的金额

P = int(input("Enter starting principle please. "))
n = int(input("Enter number of compounding periods per year. "))
r = float(input("Enter annual interest rate. e.g. 15 for 15% "))
y = int(input("Enter the amount of years. "))

FV = P * (((1 + ((r/100.0)/n)) ** (n*y)))

print ("The final amount after", y, "years is", FV)

对于复利,请尝试以下Python代码:

p = float(input('Please enter principal amount:'))
t = float(input('Please enter number of years:'))
r = float(input('Please enter rate of interest:'))
n = float(input('Please enter number of times the interest is compounded in a year:'))
a = p*(1+(r/(100*n))**(n*t))
print('Amount compounded to: ', a)

对于复利,请尝试以下Python代码:

p = float(input('Please enter principal amount:'))
t = float(input('Please enter number of years:'))
r = float(input('Please enter rate of interest:'))
n = float(input('Please enter number of times the interest is compounded in a year:'))
a = p*(1+(r/(100*n))**(n*t))
print('Amount compounded to: ', a)

每年计算复利的公式为

A=p(1+R/100)t

复利=A–p

在哪里,, A是金额, P是本金, R是比率和 T是时间跨度

def compound_interest(principal, rate, time):
    Amount = principal * (pow((1 + rate / 100), time)) 
    CI = Amount - principal
    print("Compound interest is", CI) 
compound_interest(100000000, 14, 8) 

每年计算复利的公式为

A=p(1+R/100)t

复利=A–p

在哪里,, A是金额, P是本金, R是比率和 T是时间跨度

def compound_interest(principal, rate, time):
    Amount = principal * (pow((1 + rate / 100), time)) 
    CI = Amount - principal
    print("Compound interest is", CI) 
compound_interest(100000000, 14, 8) 

为什么应该是1000.10?如果我理解正确,年复合利率为0.01,因此1000*(1.01)^1=1010.0。我是不是漏掉了什么?当我用复利计算器对答案进行三重检查时,它给了我1000.10。增加了一个答案。请检查这是否是您想要的。为什么应该是1000.10?如果我理解正确,年复合利率为0.01,因此1000*(1.01)^1=1010.0。我是不是漏掉了什么?当我用复利计算器对答案进行三重检查时,它给了我1000.10。增加了一个答案。请检查这是否是你想要的。我都没想过。谢谢,我现在就运行它,让你知道。它很有效!谢谢,早上6点就开始做这些项目了,真不敢相信我错过了。感谢@SagarWelcome的帮助。如果答案解决了你的问题,请接受呸。我都没想过。谢谢,我现在就运行它,让你知道。它很有效!谢谢,早上6点就开始做这些项目了,真不敢相信我错过了。感谢@SagarWelcome的帮助。如果答案解决了你的问题,请接受P