Python program to find the roots of quadratic equation

710
Python program to find the roots of quadratic equation
from math import sqrt
a=float(input("Please enter first number: "))
b=float(input("Please enter second number: "))
c=float(input("Please enter third number: "))
d=b*b-4*a*c; # finding determinant 
if(d==0): # when d is 0 both the roots will be equal 
   print("\n roots are equal \n");
   root1=root2=-b/(2*a);
   print("root1=" ,root1, " root2=",root2,);
elif(d>0): # roots are real and distinct 
     print("\n roots are real and distinct \n");
     root1=(-b+sqrt(d))/(2*a);
     root2=(-b-sqrt(d))/(2*a);
     print("root1=" ,root1, " root2=",root2,);
 # when d is -ve it is not possible to take the squareroot of -ve number, we have to take absolute value of d 
else:
    print("\n roots are imaginary \n");
    root1=-b/(2*a);
    root2=sqrt(-d)/(2*a);
    print("real part= " ,root1, "imaginary part= " ,root2,);

    Output 1:
             Please enter first number: 2
             Please enter second number: 2
             Please enter third number: 2
              roots are imaginary 
             real part=  -0.5 imaginary part=  0.8660254037844386
    Output 2:
             Please enter first number: 2
             Please enter second number: 5
             Please enter third number: 1
              roots are real and distinct 
             root1= -0.21922359359558485  root2= -2.2807764064044154
    Output 3:
             Please enter first number: 1
             Please enter second number: 2
             Please enter third number: 1
              roots are equal 
             root1= -1.0  root2= -1.0

इन्हें भी देखें।

Python Programs के लिये यहाँ click करें।

 

 

Python program to find the roots of quadratic equation Python program to finding the roots of quadratic equation program to finding the roots of quadratic equation in python write a program to finding the roots of quadratic equation write a program to finding the roots of quadratic equation in python program to finding the roots of quadratic equation roots of quadratic equation program program of roots of quadratic equation write a python program to find the roots of a quadratic equation program to find roots of a quadratic equation in python python program to solve quadratic equations having real roots only python program to calculate and print roots of quadratic equation python program to print roots of a quadratic equation write a python program to print roots of quadratic equation python program to find square root of quadratic equation program to find square root of quadratic equation in python program to find square root of quadratic equation python program to calculate the square root program to calculate the square root in python Python program to solve quadratic equation