#quadLoop.py #solve as many quadratic equations as user wants. #Ensure coefficient a is not zero. import math again = 'y' while again == 'y': print("Solve a quadratic equation. Enter the coefficients of a quadratic equation ") a = eval(input("Enter a: ")) while a == 0: #ensure that a is not zero a = eval(input("a can not be 0. Enter a again: ")) b = eval(input("Enter b: ")) c = eval(input("Enter c: ")) discriminant = b**2 - 4*a*c if discriminant > 0: # calculate the two possible real values 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 root x1 = -b / (2*a) print("One root (solution) x=", x1) else: #no real roots print("No roots. Discriminant is negative.") again = input("Again? (y or n): ") """ 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 """