Untitled
unknown
plain_text
a year ago
1.2 kB
4
Indexable
Never
#The program solves quadratic # #Laboratory Work #2 #Subject Theme: Python Basyc syntax. Conditional statements #version 2023.2 #Author: HolyMolly #Company# FITR BNTU #Date: 10.08.2023 import math def SolveQuadraticEquation(a, b, c): if a != 0: discriminant = b ** 2 - 4 * a * c if discriminant > 0: x1 = (-b + math.squrt(discriminant)) / (2 * a) x2 = (-b - math.squrt(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 isn`t real roots of equation." else: msg = "Input error: the first coefficient must be nonzero" return msg #Main program print("The program solves quadric 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 the enter for exit...")