EvilZone

Programming and Scripting => Scripting Languages => : Cozy Chameleon October 01, 2012, 06:50:37 AM

: i need help with a some python code(newbie stuff)
: 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)
: Re: i need help with a some python code(newbie stuff)
: RedBullAddicted October 01, 2012, 07:22:54 AM
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.
: Re: i need help with a some python code(newbie stuff)
: s3my0n October 01, 2012, 07:40:03 AM
: (python)
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)
: Re: i need help with a some python code(newbie stuff)
: HeRo October 02, 2012, 05:46:10 PM
This is OT, but I'm just amused that I somehow understood the code. O: I'm learning holy cow!
: Re: i need help with a some python code(newbie stuff)
: relax October 02, 2012, 07:22:09 PM
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?
: Re: i need help with a some python code(newbie stuff)
: 2r October 02, 2012, 08:46:39 PM
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)
: Re: i need help with a some python code(newbie stuff)
: s3my0n October 02, 2012, 10:55:49 PM
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).