write a python program that computes the real roots of a given quadratic equation (use math library)

 

from math import *
a=float(input("Enter a"))
b=float(input("Enter b"))
c=float(input("Enter c"))

Discriminant = b**2 - 4*a*c

if Discriminant > 0:
        root1 = (-b + sqrt(Discriminant)) / (2 * a)
        root2 = (-b - sqrt(Discriminant)) / (2 * a)
        print(f"Two real roots: {root1} and {root2}")
elif Discriminant == 0:
        root = -b / (2 * a)
        print(f"One real root: {root}")
else:
        print("No real roots")

'''
output:
Enter a1
Enter b-2
Enter c1
One real root: 1.0
'''
       

Comments