project_python/2.2_lesson.17.20.py
2025-12-15 13:32:14 +05:00

19 lines
928 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

****Задание 17 Параграф 2.2***
***Знаете ли вы, что Python изначально создавался для решения математических задач? Давайте воспользуемся его возможностями и найдём корни уравнения, используя составные условные операции.***
if name == "main":
a, b, c = float(input()), float(input()), float(input())
if not a and not b and not c:
print('Infinite solutions')
elif not a and not b and c or b ** 2 < 4 * a * c:
print('No solution')
elif b ** 2 == 4 * a * c:
print(f'{-b / (2 * a):.2f}')
elif not a:
print(f'{-c / b:.2f}')
else:
roots = [(-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a), (-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)]
roots.sort()
print(f'{roots[0]:.2f} {roots[1]:.2f}')