Created
June 26, 2013 01:47
-
-
Save TomDeBeauchamp/5864128 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def roots(a,b,c): | |
d = b**2-4*a*c | |
#print d | |
if d < 0: | |
return "Too complex.", "d =" + str(d) | |
elif d == 0: | |
r1=-b/2*a | |
return r1, "d =" + str(d) | |
else: | |
r1 = (-b + math.sqrt(d))/(2*a) | |
r2 = (-b - math.sqrt(d))/(2*a) | |
return "There are two real roots: " + str(r1) + ", or " + str(r2), "d =" + str(d) | |
print "roots(1,2,1) = ", roots(1,2,1) | |
print "roots(0,0,0) = ", roots(0,0,0) | |
print "roots(100,200,1000)" , roots(100,200,1000) | |
print "roots(8,3,1)", roots(8,3,1) | |
print "roots(4**3,3/8,1-23)" , roots(4**3,3/8,1-23) | |
print "roots(88,32,611)", roots(88,32,611) | |
print "roots(222,333,11)", roots(222,333,11) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment