简体   繁体   中英

Int object is not callable in Investment (interest) Calculator

I am trying to print an answer to my compounding interest formula, but it keeps saying that my integer isn't callable.

#Ask user what P equals
P = int(input('What is the initial investment? '))
#Ask user for the meaning of r
r = int(input('What is the annual nominal interest rate? '))
#Ask user for meaning of n
n = int(input('How many times will your interest compound this year? '))
#Ask user for t 
t = int(input('How many years are you planning to invest? '))
#Compute compounding interest formula 
A = P(1+(r/n))**nt
#convert line 30 into a String 
A = str(A)
#Print statement
print('You will have $',A, "in", t, 'years.')

On this line

A = P(1+(r/n))**nt

I assume you meant to do multiplication?

A = P*(1+(r/n))**(n*t)

Also note you need // to do "true division" instead of integer division

r // n

First of all you forget to do multiplication, result got an error.

here is the correct way

A = P*(1+(r/n))**(n*t)

or

Instead of using ** you can also use python's builtin function called pow

The pow() function returns the value of x to the power of y (x^y).

A = P * (pow((1 + r / n),(n*t))) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM