We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 9c09f64 + 03e3a21 commit 86e3394Copy full SHA for 86e3394
Math/quadratic_equation_solver.py
@@ -0,0 +1,24 @@
1
+import cmath
2
+
3
4
+def solve_quadratic(a, b, c):
5
+ if a == 0:
6
+ raise ValueError("Coefficient 'a' must be non-zero for a quadratic equation.")
7
8
+ discriminant = b**2 - 4 * a * c
9
10
+ root1 = (-b + cmath.sqrt(discriminant)) / (2 * a)
11
+ root2 = (-b - cmath.sqrt(discriminant)) / (2 * a)
12
13
+ return root1, root2
14
15
16
+try:
17
+ a = float(input("Enter coefficient a: "))
18
+ b = float(input("Enter coefficient b: "))
19
+ c = float(input("Enter coefficient c: "))
20
21
+ roots = solve_quadratic(a, b, c)
22
+ print(f"The roots of the equation are: {roots[0]} and {roots[1]}")
23
+except ValueError as e:
24
+ print(e)
0 commit comments