a little help with my program?

Gerhard Häring gerhard.nospam at bigfoot.de
Mon Apr 2 02:08:40 EDT 2001


johnston112 wrote:
> 
> I am trying to make a program that does performs the quadratic function.
> Here is the code:
> 
> import math
> 
> a = input ("Input a ")
> b = input ("Input b ")
> c = input ("Input c ")
> 
> x.real = -(b) + pow(b**2 - 4(a)(c)) / 2
> print x
> 
> I hope I have the actual formula right :P
> But thats not the point :) It dosn't go, could someone tell me how to fix
> it, or just a hint even, which would be better, to make me tihnk for myself
> (I am only new to python).
> Here is what it shows when i run it:
> 
> Traceback (innermost last):
>     File "d:\hacking\source\python\qf.py", line 7, in ?
>         x.real = -(b) + pow(b**2 - 4(a)(c)) / 2
> TypeError: call of non-function (type int)
> 
> So thats what I get. I have x.real because that is a floating point number
> (?) and it said something about a int type, so thats why I tried it.
> 

1) You can't name a variable "x.real". The dot is reserved for accessing
members of class instances. If you don't know what these are, don't
worry yet ;-)
2) You can't omit the "*" multiplication operator in Python: you have to
write all operators, even the implicit multiplication operators. This
will fix the TypeError, too.
3) The math module contains the pow function. You imported math with
"import math", so you have to qualify the function with the module name
prefix, like math.pow; if you want to import all the module contents in
the current namespace, import it with "from math import *"
4) Your use of the pow function lacks the exponent, my guess is that you
want it like this: math.pow( radicand, 0.5 ), or you can use the
math.sqrt function which calculates
the square root of its parameter.

Have fun :-)

Gerhard
-- 
Sorry for the fake email, please use the real one below to reply.
contact: g e r h a r d @ b i g f o o t . d e
web:     http://highqualdev.com



More information about the Python-list mailing list