EvilZone
Programming and Scripting => Scripting Languages => : Cozy Chameleon October 01, 2012, 06:50:37 AM
-
So, i am very new to python and i was wondering if someone can help me with this code. for some reason after i enter everything i get an error. can someone find and explain whats wrong with it?
thanks
p = 0
r = 0
n = 0
t = 0
x = input("what is the initial investment?")
p = int(p)
b = input("what is the anual invesment rate?")
r = float(b)
y = input("what is the number of times interest is compounded a year?")
n = int(y)
z = input("what is the number of years?")
t = int(z)
superfly = float((p(1 + (r / n) ** (n * t))))
print(superfly)
-
Hi,
I havent tried it but I guess you just missed one * after your int value p
superfly = float((p*(1 + (r / n) ** (n * t))))
Basically, when you try to execute that line the program tries to call the function p on the argument (1 + (r / n) ** (n * t)) which of course fails. Cause p is an int and no "callable" object.
I am not good with python either and maybe I am wrong but I guess it should work that way.
-
p = int(input("what is the initial investment?"))
r = float(input("what is the anual invesment rate?"))
n = int(input("what is the number of times interest is compounded a year?"))
t = int(input("what is the number of years?"))
superfly = float((p*(1 + (r / n) ** (n * t))))
print(superfly)
-
This is OT, but I'm just amused that I somehow understood the code. O: I'm learning holy cow!
-
have a noob question and i could prob look it up but iam not in a hurry
the line
superfly = float((p*(1 + (r / n) ** (n * t))))
---------------------------------^^
what dose ** do?
-
have a noob question and i could prob look it up but iam not in a hurry
the line
superfly = float((p*(1 + (r / n) ** (n * t))))
---------------------------------^^
what dose ** do?
The same thing as math.sqrt(n*t)
-
The same thing as math.sqrt(n*t)
Nope, "**" is to the power of. So it would be equivalent of math.pow(x,n*t). That is x^(n*t).