Author Topic: i need help with a some python code(newbie stuff)  (Read 1534 times)

0 Members and 1 Guest are viewing this topic.

Offline Cozy Chameleon

  • /dev/null
  • *
  • Posts: 6
  • Cookies: -2
    • View Profile
i need help with a some python code(newbie stuff)
« on: 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)

Offline RedBullAddicted

  • Moderator
  • Sir
  • *
  • Posts: 519
  • Cookies: 189
    • View Profile
Re: i need help with a some python code(newbie stuff)
« Reply #1 on: October 01, 2012, 07:22:54 am »
Hi,

I havent tried it but I guess you just missed one * after your int value p

Code: [Select]
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.
Deep into that darkness peering, long I stood there, wondering, fearing, doubting, dreaming dreams no mortal ever dared to dream before. - Edgar Allan Poe

Offline s3my0n

  • Knight
  • **
  • Posts: 276
  • Cookies: 58
    • View Profile
    • ::1
Re: i need help with a some python code(newbie stuff)
« Reply #2 on: October 01, 2012, 07:40:03 am »
Code: (python) [Select]
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)
« Last Edit: October 01, 2012, 07:41:51 am by s3my0n »
Easter egg in all *nix systems: E(){ E|E& };E

Offline HeRo

  • Peasant
  • *
  • Posts: 76
  • Cookies: 1
  • -HeRo
    • View Profile
Re: i need help with a some python code(newbie stuff)
« Reply #3 on: 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!

Offline relax

  • Sir
  • ***
  • Posts: 562
  • Cookies: 114
  • The one and only
    • View Profile
Re: i need help with a some python code(newbie stuff)
« Reply #4 on: 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?

Offline 2r

  • Serf
  • *
  • Posts: 28
  • Cookies: 3
    • View Profile
Re: i need help with a some python code(newbie stuff)
« Reply #5 on: 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)
Conscious Code - Blog
"Statistical fact, cops will never pull over a real man with a huge bong in his car. Why? They fear this man, they know he sees further than they and will blind them with ancient logics."

Offline s3my0n

  • Knight
  • **
  • Posts: 276
  • Cookies: 58
    • View Profile
    • ::1
Re: i need help with a some python code(newbie stuff)
« Reply #6 on: 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).
Easter egg in all *nix systems: E(){ E|E& };E