Python Program to solve Quadratic Equation

Quadratic equations are used in calculating areas,calculating a product’s profit or estimating an object’s speed.A quadratic equation is a second-degree equation.The standard form of the quadratic equation in pyhton is written as px^2+qx+r=0.The coefficients in the above equation are p,q,r.

The standatd form of the quadratic equation is ax^2+bx+c=0

a,b and c are real numbers and a!=0

Finding quadratic equation in python

The roots of a quadratic equation can be classified as:

1.If b*b<4*a*c,then roots are complex.

2.If b*b == 4*a*c,then roots are real,and both roots are the same.

3.If b*b> 4*a*c,then roots are real and different.

import math
def equationroots( x, y, z):
discri = y * y - 4 * x * z
sqrtval = math.sqrt(abs(discri))
if discri > 0:
print("real and different roots ")
print((-y + sqrtval)/(2 * x))
print((-y - sqrtval)/(2 * x))
elif discri == 0:
print(- y / (2 * x))
else:
print(- y / (2 * x)," + i", sqrt_val)
print(- y / (2 * x)," - i", sqrt_val)
x = 1
y = 10
z = -24
if x == 0:
print("Input correct quadratic equation")
else:
eqationroots(x, y, z)
output:

real and different roots are

2.0

-12.0

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top