Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
Exercise 2.5 works, I think, but with some parameters it complains that there's a 'math domain error'
import math
def roots (a,b,c):
x = (math.sqrt(b**2  4*a*c)b)/2
y = (b  math.sqrt(b**2  4*a*c)b)/2
print "x=",x
print "y=", y
 one year ago
 one year ago
Exercise 2.5 works, I think, but with some parameters it complains that there's a 'math domain error' import math def roots (a,b,c): x = (math.sqrt(b**2  4*a*c)b)/2 y = (b  math.sqrt(b**2  4*a*c)b)/2 print "x=",x print "y=", y
 one year ago
 one year ago

This Question is Closed

ScreechBest ResponseYou've already chosen the best response.0
You have to test the value of the discriminant before taking the square root. Alternatively, if you can to do the optional part and have it produce complex root. Takes a little bit of extra effort. The sqrt function is still limited to nonnegative values. So take the sqrt of the absolute value and multiply by "1J"
 one year ago
See more questions >>>
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.