eozzy
eozzy

Reputation: 68780

int object not callable error

I'm trying this example:

enter image description here

p = 10000
n = 12
r = 8
t = int(input("Enter the number of months the money will be compounded "))

a = p (1 + (r/n)) ** n,t

print (a)

.. but the error is:

TypeError: 'int' object is not callable

Is Python seeing p as a function? If so, is there no way I could do it without importing modules?

Thanks!

Upvotes: 1

Views: 1526

Answers (4)

David Robinson
David Robinson

Reputation: 78640

Change the line to

a = p * (1 + (r/n)) ** (n * t)

Python doesn't interpret variables that are next to each other as being multiplied (nor would it interpret n, t as that.

Upvotes: 5

Phil Cooper
Phil Cooper

Reputation: 5877

  1. you need the "*" operator to multiply numbers
  2. dividing int by int does not give a float so cast one to a float multiply of divide by a float (you will see "*1." in some code to do this"
  3. your input line does not match the variables above (i.e. t should be years not months and n is number of times compounded per year ... 12 for monthly and 4 for quarterly etc)
  4. also need to change your 8 to .08 as a percentage

Try:

p * (1 + (r/100.0/n)) ** (n * t)

Upvotes: -1

wim
wim

Reputation: 363566

Assuming you are using python 3..

p = 10000
n = 12
r = 8
t = int(input("Enter the number of months the money will be compounded: "))

a = p * (1 + (r / n)) ** (n * t)

print(a)

Also double check the units for t, is it in months or years? The formula seems to suggest years (if n = 12 is months per year) but you are prompting for months.

If in python 2.x you would need to import division from __future__, or convert r to float first. And you would use raw_input for the prompt.

Upvotes: 1

dkamins
dkamins

Reputation: 21948

You are trying to multiply by p, so you should be explicit and use a *:

a = p * ((1 + (float(r)/n)) ** n,t)

Cast to float (thanks David R) to prevent int rounding problems in division.

Upvotes: -1

Related Questions