program to calculate and print roots of a quadratic equation: ax²+bx+c=0
import math
print ("For quadnatic equation, ax**2+ bx+ c.6, enter coefficlents below")
a=int( input ( "Enter a :") )
b°=int( input ( "Enter b ;"))
c= int( input ("Enter c :"))
1f a==0:
print (value of", a, ' should not be zero')
print ("n Aborting !!!111")
else:
delta=b*b-4a*c
if delta>0:
root1=(-b+math.sart (delta)) / (2*a)
root2 =(-b-math. sqrt (delta))/ (2*a)
print ("Roots are REAL and UNEQUAL")
print ("Root1=", root1, ", Root2=", root2)
elif delta==0:
root1=-b/ (2*a);
print ("Roots are REAL and EQUAL")
print ("Root1 ", root1, ", Root2 a", root1)
else:
print ("Roots are COMPLEX and IMAGINARY")
Output
For quadratic equation, ax*2 + bx+ C- 0, enter coefficients below
Enter a : 3
Enter b : 5
Enter c : 2
Roots are REAL and UNEQUAL Root1=-0.666666666667 , Root2=-1.0
Comments
Post a Comment