Untitled
plain_text
2 months ago
923 B
2
Indexable
Never
import math def SolveQuadraticEquation(a, b, c): if a != 0: discriminant = b ** 2 - 4 * a * c if discriminant > 0: x1 = (-b + math.sqrt(discriminant)) / (2 * a) x2 = (-b - math.sqrt(discriminant)) / (2 * a) msg = "There are two roots of equation: x1 = {}, x2 = {}".format(x1, x2) elif discriminant == 0: x = -b / (2 * a) msg = "There is only one root of equation: x = " + str(x) else: msg = "There aren't real roots of the equation." else: msg = "Input error: the first coefficient must be nonzero" return msg # Main program print("The program solves quadratic equation: ax**2 + bx + c = 0") a = float(input("Input a: ")) b = float(input("Input b: ")) c = float(input("Input c: ")) result = SolveQuadraticEquation(a, b, c) print(result) input("\nPress enter to exit...")