complex roots
Browse files
app.py
CHANGED
|
@@ -26,18 +26,16 @@ def quadratic_roots(a:int, b:int, c:int)-> str:
|
|
| 26 |
# Calculate the discriminant
|
| 27 |
discriminant = b**2 - 4*a*c
|
| 28 |
|
| 29 |
-
if discriminant
|
| 30 |
-
#
|
| 31 |
root1 = (-b + math.sqrt(discriminant)) / (2 * a)
|
| 32 |
root2 = (-b - math.sqrt(discriminant)) / (2 * a)
|
| 33 |
-
return str(root1), str(root2)
|
| 34 |
-
elif discriminant == 0:
|
| 35 |
-
# One real root (double root)
|
| 36 |
-
root = -b / (2 * a)
|
| 37 |
-
return str(root), str(root)
|
| 38 |
else:
|
| 39 |
-
#
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
@tool
|
|
|
|
| 26 |
# Calculate the discriminant
|
| 27 |
discriminant = b**2 - 4*a*c
|
| 28 |
|
| 29 |
+
if discriminant >= 0:
|
| 30 |
+
# Real roots
|
| 31 |
root1 = (-b + math.sqrt(discriminant)) / (2 * a)
|
| 32 |
root2 = (-b - math.sqrt(discriminant)) / (2 * a)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
else:
|
| 34 |
+
# Complex roots
|
| 35 |
+
root1 = (-b + cmath.sqrt(discriminant)) / (2 * a)
|
| 36 |
+
root2 = (-b - cmath.sqrt(discriminant)) / (2 * a)
|
| 37 |
+
|
| 38 |
+
return str(root1), str(root2)
|
| 39 |
|
| 40 |
|
| 41 |
@tool
|