2019-10-29 15:23:23 +00:00
|
|
|
from math import *
|
2019-11-26 18:28:26 +00:00
|
|
|
from fractions import Fraction
|
2019-10-29 15:23:23 +00:00
|
|
|
|
2019-11-14 17:40:52 +00:00
|
|
|
|
|
|
|
def factors(n):
|
2021-04-26 07:11:02 +00:00
|
|
|
result = set()
|
|
|
|
for i in range(1, int(sqrt(n)) + 1):
|
|
|
|
if n % i == 0:
|
|
|
|
result.add(i)
|
|
|
|
result.add(n // i)
|
|
|
|
return result
|
2019-11-14 17:40:52 +00:00
|
|
|
|
|
|
|
|
2021-03-25 23:11:48 +00:00
|
|
|
def solve_quadratic(a, b, c):
|
2021-04-26 07:11:02 +00:00
|
|
|
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)))
|
2021-03-25 23:11:48 +00:00
|
|
|
else:
|
2021-04-26 07:11:02 +00:00
|
|
|
print("x = " + str(-b / (2 * a)))
|
2021-03-25 23:11:48 +00:00
|
|
|
|
|
|
|
|
2019-10-29 15:23:23 +00:00
|
|
|
print("loaded Python calculator")
|