[scripts/pycalc] add a simple as a rock quadratic equation solver

This commit is contained in:
Dmytro Meleshko 2021-03-26 01:11:48 +02:00
parent 570307f0bc
commit 4b0865b150
1 changed files with 17 additions and 0 deletions

View File

@ -11,4 +11,21 @@ def factors(n):
return result
def solve_quadratic(a, b, c):
if a == 0:
raise Exception("not a quadratic equation")
else:
d = b ** 2 - 4 * a * c
print("D = " + str(d))
if d < 0:
print("no solutions")
elif d > 0:
sd = sqrt(d)
print("sqrt(D) = " + str(sd))
print("x1 = " + str((-b + sd) / (2 * a)))
print("x2 = " + str((-b - sd) / (2 * a)))
else:
print("x = " + str(-b / (2 * a)))
print("loaded Python calculator")