Сделал 17 задание Параграф 2.2
This commit is contained in:
parent
e25a438368
commit
359f2719ba
38
2.2_lesson.17.20.py
Normal file
38
2.2_lesson.17.20.py
Normal file
|
|
@ -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}")
|
||||||
Loading…
Reference in a new issue