# Program to compute the roots of a quadratic equation # (user enters coefficients) # Matt Bishop, May 1, 2009 # for ECS 10 Spring 2009 import math # load up the math functions # compute the discriminant # parameters: a, b, c: coefficients # returns: b^2 -4acv def discrim(a, b, c): return b * b - 4 * a * c; def main(): # read in the coefficients a, b, c = input("Enter coefficents (a,b,c) separated by commas: "); # get the discriminant d = discrim(a, b, c); if (d < 0): print "The roots are complex numbers"; else: # get the first root r1 = (-b + math.sqrt(d)) / (2*a); # get the second root r2 = (-b - math.sqrt(d)) / (2*a); # print them out print "The roots are", r1, "and", r2; main()