Header Ads Widget

Python program to determine the roots of quadratic equation

 

Python program to determine the roots of quadratic equation

The objective of the code is to find the roots of the quadratic equation . For calculating the roots of the quadratic equation we will use the formula . 

Sample input 
2 3 1
Sample output
Roots of the equation are: -0.5 and -1



 Code(Python):-

import math
print("Enter the coefficient of the each term of the quadratic equation")
a,b,c=map(int,input().split())
D=(b*b)-(4*a*c);
if(D<0):
print("_Imaginary roots")
else:
m=math.sqrt(D);
x1=(-b+m)/(2*a);
x2=(-b-m)/(2*a);
print(f"Roots of the equation are: {x1} and {x2}")


Output:-


Enter the coefficient of the each term of the quadratic equation
2 3 1
Roots of the equation are: -0.5 and -1.0


Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

Post a Comment

0 Comments