From 359f2719bad0b4f3de37d6f76ecbf6f1ac7f3d64 Mon Sep 17 00:00:00 2001 From: Zver Date: Mon, 1 Dec 2025 15:56:42 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=2017=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=9F=D0=B0=D1=80?= =?UTF-8?q?=D0=B0=D0=B3=D1=80=D0=B0=D1=84=202.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.2_lesson.17.20.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 2.2_lesson.17.20.py diff --git a/2.2_lesson.17.20.py b/2.2_lesson.17.20.py new file mode 100644 index 0000000..baaf73d --- /dev/null +++ b/2.2_lesson.17.20.py @@ -0,0 +1,38 @@ +''' ****** Задание 17(Q) из 20 Параграф 2.2 ********* +* Знаете ли вы, что Python изначально создавался для решения математических задач? + Давайте воспользуемся его возможностями и найдём корни уравнения, используя составные условные операции. +''' + + +if __name__ == "__main__" + import math + + try: + a = float(input()) + b = float(input()) + c = float(input()) + except ValueError: + print("Ошибка: введите корректные числовые значения.") + exit() + + if a == 0 and b == 0: + if c == 0: + print("Infinite solutions") + else: + print("No solution") + elif a == 0: + root = -c / b + print(f"{root:.2f}") + else: + discriminant = b ** 2 - 4 * a * c + if discriminant < 0: + print("No solution") + elif discriminant == 0: + root = -b / (2 * a) + print(f"{root:.2f}") + else: + root1 = (-b - math.sqrt(discriminant)) / (2 * a) + root2 = (-b + math.sqrt(discriminant)) / (2 * a) + if root1 > root2: + root1, root2 = root2, root1 + print(f"{root1:.2f} {root2:.2f}")