print('введите a') a = float(input("a = ")) b = float(input("b = ")) c = float(input("c = ")) import math if a == 0: x = float(-c/b) else: discr = b ** 2 - 4 * a * c print("Дискриминант D = %.2f" % discr) if discr > 0: x1 = (-b + math.sqrt(discr)) / (2 * a) x2 = (-b - math.sqrt(discr)) / (2 * a) print("x1 = %.2f \nx2 = %.2f" % (x1, x2)) elif discr == 0: x = -b / (2 * a) print("x = %.2f" % x) else: print("Корней нет") Code print('введите a') a = float(input("a = ")) b = float(input("b = ")) c = float(input("c = ")) import math if a == 0: x = float(-c/b) else: discr = b ** 2 - 4 * a * c print("Дискриминант D = %.2f" % discr) if discr > 0: x1 = (-b + math.sqrt(discr)) / (2 * a) x2 = (-b - math.sqrt(discr)) / (2 * a) print("x1 = %.2f \nx2 = %.2f" % (x1, x2)) elif discr == 0: x = -b / (2 * a) print("x = %.2f" % x) else: print("Корней нет") При a=0 должна работать формула -c/b, но выдаёт ошибку. Можете помочь?
Если при a==0 тебе не нужен дискриминант, то зачем ты его используешь в следующих условных операторах? По-моему должно быть примерно вот так import math print('введите a') a = float(input("a = ")) b = float(input("b = ")) c = float(input("c = ")) if a == 0: x = float(-c/b) print(x) else: discr = b ** 2 - 4 * a * c print("Дискриминант D = %.2f" % discr) if discr > 0: x1 = (-b + math.sqrt(discr)) / (2 * a) x2 = (-b - math.sqrt(discr)) / (2 * a) print("x1 = %.2f \nx2 = %.2f" % (x1, x2)) elif discr == 0: x = -b / (2 * a) print("x = %.2f" % x) else: print("Корней нет") Python import math print('введите a') a = float(input("a = ")) b = float(input("b = ")) c = float(input("c = ")) if a == 0: x = float(-c/b) print(x) else: discr = b ** 2 - 4 * a * c print("Дискриминант D = %.2f" % discr) if discr > 0: x1 = (-b + math.sqrt(discr)) / (2 * a) x2 = (-b - math.sqrt(discr)) / (2 * a) print("x1 = %.2f \nx2 = %.2f" % (x1, x2)) elif discr == 0: x = -b / (2 * a) print("x = %.2f" % x) else: print("Корней нет")