#quad1.py Version 1 # This program computes the quadratic formula. It asks the user # to enter the three coefficients of a quadratic equation. # The two possible solutions for the variable are determined. # NB. crashes if radicand is negative, i.e. no solutions case. import math #input the coefficients a = eval(input("Enter a: ")) b = eval(input("Enter b: ")) c = eval(input("Enter c: ")) # calculate the two possible values for x. x1 = (-b + math.sqrt(b**2 - 4*a*c)) / (2 * a) x2 = (-b - math.sqrt(b**2 - 4*a*c)) / (2 * a) #display the two solutions print("x1:", x1, " x2:", x2) # Example inputs-output # 1 1 -2 1 -2 # -1 1 2 -1 2 # 1 -1 -1 phi 1-phi