def drange(x, y, jump) -> float: # Генератор чисел float import decimal while x < y: yield float(x) x += decimal.Decimal(jump) def viet(a, b, c): # Подбор корней по теореме Виетта D = (b**2 - 4*a*c)**0.5 x1 = x2 = 0 points = [i for i in drange(-5, 5, '0.001')] if D > 0: for i in points: x1 = i for j in points: x2 = j if round(x1 + x2, 2) == round(-b / a, 2) and round(x1 * x2, 2) == round(c / a, 2): return x1, x2 if D == 0: for i in points: x1 = i if round(2 * x1, 2) == round(-b / a, 2) and round(x1 ** 2, 2) == round(c / a, 2): return x1 if D < 0: print('Корней нет!') a, b, c = float(input('a = ')), float(input('b = ')), float(input('c = ')) print(viet(a, b, c))
The list of root points here is from -5 to 5 with an accuracy of up to 0.001, i.e. 10,000 options. Increasing the range, increases the time of the search.