Anath3ma
Anath3ma

Reputation: 45

Python Compound Interest Not Working

Here's what I have so far, I think it's complete and I have zero errors other than the fact that the output is just 10,000 (which is way wrong, I've been using 15 years as "t"). I've looked around at similar questions and followed a few of the suggestions but nothing has fixed it. Is there just something silly I'm missing? Thanks!

print ("Hello, this program will calculate compound interest with a rate of 8%, a principal of 10,000 dollars, on a 12 month cycle (where n is 12)")
p = 10000.00
r = .08
n = 12
t = int(input("Please enter the length of time for the interest to be compounded: "))
amount = (p*(1+(r//(100.0*n))**(n*t)))
print ("The final amount is",amount,"for an initial investment of 10,000, with a rate of 8% and compounded monthly over",t,"years.")

Upvotes: 0

Views: 895

Answers (1)

The_Coder
The_Coder

Reputation: 321

As mentioned in my comment, your code doesn't capture the actual formula very well. Check the brackets properly.

print ("Hello, this program will calculate compound interest with a rate of 8%, a     principal of 10,000 dollars, on a 12 month cycle (where n is 12)")
p = 10000.00
r = .08
n = 12
t = int(input("Please enter the length of time for the interest to be compounded: "))
amount = p*((1+(r/(100*n)))**(n*t))
print ("The final amount is",amount,"for an initial investment of 10,000, with a rate of 8% and compounded monthly over",t,"years.")

Result: 10120.718840552334

Upvotes: 1

Related Questions