This Python code imports the complex math module to solve a quadratic equation of the form ax^2 + bx + c = 0. It defines coefficients a, b, c, calculates the discriminant, and finds the two solutions by using the quadratic formula and printing the results.
Download as DOC, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
57 views
Python Program To Solve The Quadratic Equation
This Python code imports the complex math module to solve a quadratic equation of the form ax^2 + bx + c = 0. It defines coefficients a, b, c, calculates the discriminant, and finds the two solutions by using the quadratic formula and printing the results.
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1
# 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))/(2*a) print('The solution are {0} and {1}'.format(sol1,sol2))