How to find roots of quadratic equation using python code

In this tutorial, we are going to show How to find roots of quadratic equation using python code. We have added the video tutorial and the source code of the program.

Video Tutorial: Find roots of quadratic equation using python code

Source Code

# Python program to find roots of
# Quadratic Equation 

import cmath 

a = float(input("Enter value of a : ")) 
b = float(input("Enter value of b : ")) 
c = float(input("Enter value of c : ")) 

d = (b**2) - (4*a*c) 

root1 = (-b-cmath.sqrt(d))/(2*a) 
root2 = (-b+cmath.sqrt(d))/(2*a) 

print("\nRoot 1 : ",root1) 
print("\nRoot 2 : ",root2) 

Output

Also Read: Python program to create bmi calculator

Join Now : Learn Python Programming Masterclass

Leave a Reply

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