#quadIf.py #solve a quadratic equation. Three cases. import math print("Solve a quadratic equation. Enter the coefficients of a quadratic equation ") a = eval(input("Enter a: ")) if a == 0: print("a can not be 0. Quitting") quit() b = eval(input("Enter b: ")) c = eval(input("Enter c: ")) discriminant = b**2 - 4*a*c if discriminant > 0: # calculate the two possible real value solutions for x. x1 = (-b + math.sqrt(discriminant)) / (2 * a) x2 = (-b - math.sqrt(discriminant)) / (2 * a) print("Two roots (solutions) x1:", x1, " x2: ", x2) elif discriminant == 0: #one real solution x1 = -b / (2*a) print("One solution x=", x1) else: #no real solutions print("No solutions. Discriminant is negative.") """ 1 1 -2 1 -2 -1 1 2 -1 2 2 2 -2 0.618034 -1.61803 1 1 1 no roots 1 2 1 one root -1 """