Python Programming: Roots of Quardratic Equation
#Finding Roots of a quardratic Equation
import math
a=int(input("Enter the value of a : "))
b=int(input("Enter the value of b : "))
c=int(input("enter the value of c : "))
dis=b**2-4*a*c # finding discriminant
if(dis>0):
print("Roots are Real and unequal")
sq=math.sqrt(dis)
r1=(-b+sq)/(2*a)
r2=(-b-sq)/(2*a)
elif(dis<0):
print("Roots are Imaginary ")
r1=complex(-b,math.sqrt(abs(dis)))/(2*a)
r2 = complex(-b, -math.sqrt(abs(dis))) / (2 * a)
else:
print("Roots are Real and Equal")
r1 = -b / (2 * a)
r2 = r1
print("Roots are : r1=", r1, ", r2=", r2)
import math
a=int(input("Enter the value of a : "))
b=int(input("Enter the value of b : "))
c=int(input("enter the value of c : "))
dis=b**2-4*a*c # finding discriminant
if(dis>0):
print("Roots are Real and unequal")
sq=math.sqrt(dis)
r1=(-b+sq)/(2*a)
r2=(-b-sq)/(2*a)
elif(dis<0):
print("Roots are Imaginary ")
r1=complex(-b,math.sqrt(abs(dis)))/(2*a)
r2 = complex(-b, -math.sqrt(abs(dis))) / (2 * a)
else:
print("Roots are Real and Equal")
r1 = -b / (2 * a)
r2 = r1
print("Roots are : r1=", r1, ", r2=", r2)
Comments
Post a Comment