Skip to content

Commit 3b47549

Browse files
Python Program to Solve Quadratic Equation
This program computes roots of a quadratic equation when coefficients a, b and c are known.
1 parent ebfd55d commit 3b47549

File tree

1 file changed

+17
-0
lines changed
  • # Solve the quadratic equation ax**2 + bx + c = 0 # import complex math module import cmath a = 1 b = 5 c = 6 # calculate the discriminant d = (b**2) - (4*a*c) # find two solutions sol1 = (-b-cmath.sqrt(d))/(2*a) sol2 = (-b+cmath.sqrt(d))

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Solve the quadratic equation ax**2 + bx + c = 0
2+
3+
# import complex math module
4+
import cmath
5+
6+
a = 1
7+
b = 5
8+
c = 6
9+
10+
# calculate the discriminant
11+
d = (b**2) - (4*a*c)
12+
13+
# find two solutions
14+
sol1 = (-b-cmath.sqrt(d))/(2*a)
15+
sol2 = (-b+cmath.sqrt(d))/(2*a)
16+
17+
print('The solution are {0} and {1}'.format(sol1,sol2))

0 commit comments

Comments
 (0)