[Tutor] faulty code (maths)

David ldl08 at gmx.net
Sun Nov 23 14:39:01 CET 2008

Hello Kent,

yes, the error message - sorry:

When I just run line 3, I get:

In [7]:  q = sqrt(b*b - 4*a*c)
<type 'exceptions.ValueError'>            Traceback (most recent call last)

/home/david/Documents/Python/myCode/Langtangen/py1st/<ipython console> 
in <module>()

<type 'exceptions.ValueError'>: math domain error

In [8]:

Ah! It's a not a Python, but a math error - I am trying to take a root 
of a negative number!

Thanks for the help!


Kent Johnson wrote:
> On Sun, Nov 23, 2008 at 6:37 AM, David <ldl08 at gmx.net> wrote:
>> I am trying to solve exercise 1.18 ("Why does the following program not work
>> correctly?"), but I don't find the mistake: why does the line
>> q = sqrt(b*b - 4*a*c)
>> cause an error? I was playing around with the code, but got nowhere.
> Did you get an error? What was it? Please show the entire error
> message, including the stack trace, when you have a question about an
> error.
> What is the value of (b*b - 4*a*c) ? Does that give you a hint?
> Kent

More information about the Tutor mailing list