Quadratic Equation in Python Without Lambda

(Last Updated On: 06/12/2022)

Python Program to Find Out the Roots of the Quadratic Equation Without Lambda

# Python Program to Find Out the Roots of the Quadratic Equation Without Lambda

# import complex math module
import cmath

# we are taking a number from user as input
# entered value will be converted to int from string
a=int(input("Enter first number:"))
b=int(input("Enter second number:"))
c=int(input("Enter third number:"))

# 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))

Output:

Enter first number:1
Enter second number:5
Enter third number:6
The solution are (-3+0j) and (-2+0j)