Reputation: 68780
I'm trying this example:
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
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
Reputation: 5877
Try:
p * (1 + (r/100.0/n)) ** (n * t)
Upvotes: -1
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
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