Solving a quadratic equation

Import Math
 Import the cmath 

Print ( " Please enter the three coefficients of a quadratic equation the ABC: " ) 
A = a float (INPUT ( " A = " )) 
B = a float (INPUT ( " B = " )) 
C = a float (INPUT ( " C = " ))
 IF A == 0:
     IF B == 0:
         IF ! C = 0:
             Print ( " no solution! " )
         the else :
             Print ( "x is a plurality of sets of any solutions of infinite " )
     the else :
         Print ( " x = " , -C / B)
 the else : 
    Die = B * B -. 4 * A * C
     IF Die < 0:
         Print ( " no solution in the real number range " ) 
        X1 = Complex (-B / (2 * A), Complex (0, cmath.sqrt (Die) / (2 * A))) 
        X2 = Complex (-B / (2 * A), Complex (0, -cmath.sqrt (Die) / (2 * a)))
         Print ( " solution within the scope of the following complex " )
         Print ( "x1 =", x1)
        print("x2 =", x2)
    elif die == 0:
        print("x1 = x2 =", -B / (2 * A))
    else:
        x1 = (-B + math.sqrt(die)) / (2 * A)
        x2 = (-B - math.sqrt(die)) / (2 * A)
        print("x1 =", x1)
        print("x2 =", x2)

 

Guess you like

Origin www.cnblogs.com/Chaosliang/p/11595055.html