Python Program to Find Roots of Quadratic Equation
Write Python Program to Find Roots of Quadratic Equation
# Python Program to Find Roots of Quadratic Equation
from math import sqrt
# get the value of cefficient
a = float(input("Enter Coefficient a :--> "))
b = float(input("Enter Coefficient b :--> "))
c = float(input("Enter Coefficient c :--> "))
delta = b * b - 4 * a * c
root1 = (-b + sqrt(delta)) / (2 * a)
root2 = (-b - sqrt(delta)) / (2 * a)
print("Root 1 = ", root1)
print("Root 2 = ", root2)
Output:
Enter Coefficient a :--> 4
Enter Coefficient b :--> 8
Enter Coefficient c :--> 2
Root 1 = -0.2928932188134524
Root 2 = -1.7071067811865475