Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 7 Online
OpenStudy (anonymous):

I need some help on this practice problem for Python.Positive root of the following equation: 34*x^2 + 68*x - 510 Recall: a*x^2 + b*x + c x1 = ( - b + sqrt ( b*b - 4*a*c ) ) / ( 2*a ) what I typed is... >>> import math >>> math.sqrt(68*68-4*34*-510) 272.0 >>> (-68+sqrt(68*68-4*34*-510))/(2*34) but I keep getting Traceback (most recent call last): File "", line 1, in (-68+sqrt(68*68-4*34*-510))/(2*34) NameError: name 'sqrt' is not defined Can anyone help me with this and explain it? Thanks a lot. I am a beginner...

OpenStudy (anonymous):

what were you expecting when you wrote "(-68+sqrt(68*68-4*34*-510))/(2*34)" ?

OpenStudy (anonymous):

You either need to do: "from math import* if you don't want to type math.sqrt(2) and just say sqrt(2) or "from math import as m" so you could use m.sqrt(2). All I know is that how importing and using libraries works in python.

OpenStudy (anonymous):

Hi thank you for your reply. When I wrote "(-68+sqrt(68*68-4*34*-510))/(2*34)" , I was expecting to get the final result.But I didn't get the final result, I got NameError: name 'sqrt' is not defined instead.

OpenStudy (anonymous):

"(-68+math.sqrt(68*68-4*34*-510))/(2*34)" is what you would want then in your case

OpenStudy (anonymous):

Thank you so much, salb

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!