Learn Before
Python Program to Solve Quadratic Equations
The standard form of a quadratic equation is:
ax^2 + bx + c = 0
where a, b, and c are real numbers and a ≠ 0
The solutions of this quadratic equation is given by:
(-b ± (b^2 - 4 * a * c)^0.5) / (2 * a)
Source Code
#Solve the quadratic equation ax^2 + bx + c = 0
#Import complex math module
import cmath
#Define variables
a = float (input ("Enter the value of a: "))
b = float (input ("Enter the value of b: "))
c = float (input ("Enter the value of c: "))
#Calculate the discriminant
d = (b**2) - (4ac)
#Solve for the two solutions
sol1 = (-b - cmath.sqrt(d))/(2*a)
sol2 = (-b + cmath.sqrt(d))/(2*a)
print ("The solutions are {0} and {1}".format (sol1, sol2))
0
1
Tags
Python Programming Language
Data Science
Related
Having Fun with Conditional Statements in Python
Python Standard Library
BioPython
BioPython Tutorial
Bioinformatics Textbook
Five Cool Things You Can Do with Python
Thing You Can Do with Python
Python Program to Make a Simple Calculator
Python Program to Display Calendar
Python Program to Create Pyramid Patterns
Python Program to Solve Quadratic Equations