Untitled
unknown
plain_text
a year ago
1.6 kB
14
Indexable
Never
a = float(input()) b = float(input()) c = float(input()) if a == 0: if b == 0: # 0x^2+0x+0=0 print("Infinite solutions") else: if c == 0: # bx = 0 x1: float = 0.0 print(x1) else: # bx + c = 0 x1: float = round(-c / b, 2) print(x1) else: if b == 0: if c == 0: # ax^2 = 0 x1: float = 0.0 print(x1) else: # ax^2+c=0 if (-c / a) >= 0: x1 = round((-c / a) ** (1 / 2), 2) x2 = round(-1 * ((-c / a) ** (1 / 2)), 2) if x1 == x2: print(x1) else: print(f"{min(x1, x2)} {max(x1, x2)}") else: # x^2 = -c/a < 0 print("No solution") else: if c == 0: # ax^2+bx=0 d: float = b ** 2 x1: float = round((-b + d ** (1 / 2)) / (2 * a), 2) x2: float = round((-b - d ** (1 / 2)) / (2 * a), 2) print(f"{min(x1, x2)} {max(x1, x2)}") else: # ax^2+bx+c=0 d: float = b ** 2 - 4 * a * c if d < 0: print("No solution") else: x1: float = round((-b + d ** (1 / 2)) / (2 * a), 2) x2: float = round((-b - d ** (1 / 2)) / (2 * a), 2) if x1 == x2: print(x1) else: print(f"{min(x1, x2)} {max(x1, x2)}")