def sqrt(n):
x = n
y = 1.0
eps = 0.00001
while x - y > eps:
x = (x + y) / 2
y = n / x
return x
# Viete's rules = Relatiile lui Viete
# ax^2 + bx + c = 0; a != 0
# x^2 - Sx + P = 0
# S = x1 + x2
# P = x1 * x2
# S = -b/a; P = c/a
# the study of the sign roots of a Quadratic Equation
def Nature_Roots_Quadratic_Equation(a, b, c):
d = b ** 2 - 4 * a * c
#a!=0
S = -b/a
P = c/a
print(f"Sum = {S}, Prod = {P}")
print("Sum = %.2f Prod = %.2f"%(S, P))
if d < 0:
return ["imaginary"]
elif d >= 0:
x1 = ( -b - sqrt(d) )/ (2*a)
x2 = ( -b + sqrt(d) ) / (2*a)
print(f"x1={x1:.2f} x2={x2:.2f}")
if S > 0:
if P > 0:
return ["x1>0","x2>0"]
elif P < 0:
return ["x1<0","x2>0","|x1|<|x2|"]
#x1=-3, x2=7
else:
return ["x1=0","x2>0"]
# S < 0
else:
if P > 0:
return ["x1<0","x2<0"]
elif P < 0:
return ["x1<0","x2>0","|x1|>|x2|"]
else:
return ["x1=0","x2<0"]
def main():
lesson = dict(title = "Viete's Rules", content ="\nNature Roots Quadratic Equation")
print("Today we'll learn about:\n{title} {content}".format(**lesson))
A = 1
B = 5
C = 2
print(*Nature_Roots_Quadratic_Equation(A,B,C), sep="\n")
main()
ZGVmIHNxcnQobik6CiAgICB4ID0gbgogICAgeSA9IDEuMAogICAgZXBzID0gMC4wMDAwMQogICAgd2hpbGUgeCAtIHkgPiBlcHM6CiAgICAgICAgeCA9ICh4ICsgeSkgLyAyCiAgICAgICAgeSA9IG4gLyB4CiAgICByZXR1cm4geAojIFZpZXRlJ3MgcnVsZXMgPSBSZWxhdGlpbGUgbHVpIFZpZXRlCiMgYXheMiArIGJ4ICsgYyA9IDA7IGEgIT0gMAojIHheMiAtIFN4ICsgUCA9IDAKIyBTID0geDEgKyB4MgojIFAgPSB4MSAqIHgyCiMgUyA9IC1iL2E7IFAgPSBjL2EKIyB0aGUgc3R1ZHkgb2YgdGhlIHNpZ24gcm9vdHMgb2YgYSBRdWFkcmF0aWMgRXF1YXRpb24KZGVmIE5hdHVyZV9Sb290c19RdWFkcmF0aWNfRXF1YXRpb24oYSwgYiwgYyk6CiAgICBkID0gYiAqKiAyIC0gNCAqIGEgKiBjCiAgICAjYSE9MAogICAgUyA9IC1iL2EKICAgIFAgPSBjL2EKCiAgICBwcmludChmIlN1bSA9IHtTfSwgUHJvZCA9IHtQfSIpCiAgICBwcmludCgiU3VtID0gJS4yZiBQcm9kID0gJS4yZiIlKFMsIFApKQogICAgaWYgZCA8IDA6CiAgICAgICAgcmV0dXJuIFsiaW1hZ2luYXJ5Il0KICAgIGVsaWYgZCA+PSAwOgogICAgICAgICB4MSA9ICggLWIgLSBzcXJ0KGQpICkvICgyKmEpCiAgICAgICAgIHgyID0gKCAtYiArIHNxcnQoZCkgKSAvICgyKmEpCiAgICAgICAgIHByaW50KGYieDE9e3gxOi4yZn0geDI9e3gyOi4yZn0iKQogICAgICAgICBpZiBTID4gMDoKICAgICAgICAgICAgIGlmIFAgPiAwOgogICAgICAgICAgICAgICAgIHJldHVybiBbIngxPjAiLCJ4Mj4wIl0KICAgICAgICAgICAgIGVsaWYgUCA8IDA6CiAgICAgICAgICAgICAgICAgcmV0dXJuIFsieDE8MCIsIngyPjAiLCJ8eDF8PHx4MnwiXQogICAgICAgICAgICAgICAgICN4MT0tMywgeDI9NwogICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgICByZXR1cm4gWyJ4MT0wIiwieDI+MCJdCiAgICAgICAgICMgUyA8IDAKICAgICAgICAgZWxzZToKICAgICAgICAgICAgIGlmIFAgPiAwOgogICAgICAgICAgICAgICAgIHJldHVybiBbIngxPDAiLCJ4MjwwIl0KICAgICAgICAgICAgIGVsaWYgUCA8IDA6CiAgICAgICAgICAgICAgICAgcmV0dXJuIFsieDE8MCIsIngyPjAiLCJ8eDF8Pnx4MnwiXQogICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgICByZXR1cm4gWyJ4MT0wIiwieDI8MCJdCmRlZiBtYWluKCk6CgogICAgbGVzc29uID0gZGljdCh0aXRsZSA9ICJWaWV0ZSdzIFJ1bGVzIiwgY29udGVudCA9IlxuTmF0dXJlIFJvb3RzIFF1YWRyYXRpYyBFcXVhdGlvbiIpCgogICAgcHJpbnQoIlRvZGF5IHdlJ2xsIGxlYXJuIGFib3V0Olxue3RpdGxlfSB7Y29udGVudH0iLmZvcm1hdCgqKmxlc3NvbikpCgogICAgQSA9IDEKICAgIEIgPSA1CiAgICBDID0gMgogICAgcHJpbnQoKk5hdHVyZV9Sb290c19RdWFkcmF0aWNfRXF1YXRpb24oQSxCLEMpLCBzZXA9IlxuIikKCm1haW4oKQo=