Skip to content

Instantly share code, notes, and snippets.

@TomDeBeauchamp
Created June 26, 2013 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomDeBeauchamp/5864128 to your computer and use it in GitHub Desktop.
Save TomDeBeauchamp/5864128 to your computer and use it in GitHub Desktop.
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