Take the 2-minute tour ×

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?


share|improve this question
add comment

4 Answers

up vote 1 down vote accepted

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)


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.

share|improve this answer
input works, but not raw_input NameError: name 'raw_input' is not defined –  Nimbuz Jan 11 '12 at 5:43
then you are on python 3. –  wim Jan 11 '12 at 6:25
add comment

Change the line to


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

share|improve this answer
Note: If the OP is using python 3 (which they seem to be given the print function syntax), then division is sane by default and // is integer division. –  wim Jan 11 '12 at 5:31
also i think the p should be OUTSIDE of the exponent. –  wim Jan 11 '12 at 5:32
An alternative to float(r)/n is to use from __future__ import division before any other imports. –  detly Jan 11 '12 at 5:33
Thank you for the notes- so edited. –  David Robinson Jan 11 '12 at 5:38
add comment
  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


p * (1 + (r/100.0/n)) ** (n * t)
share|improve this answer
A down vote?.. My only gripe is that the most upvoted and the accepted answers don't give the right answer with the variable inputs provided. Doesn't being right count any more?..... now you've got something to down vote....hit me ... LOL –  Phil Cooper Jan 12 '12 at 1:59
add comment

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.

share|improve this answer
add comment

Your Answer


