Python program to create quadratic Equation

from math import sqrt
x = float(input("Insert x = "))
y = float(input("Insert y = "))
z = float(input("Insert z = "))
a = y*y-4*x*z
if a>0:
 x1 = (-y + sqrt(a))/(2*x)
 x2 = (-y - sqrt(a))/(2*x)
 print("x1 = %.2f; x2 = %.2f" % (x1,x2))
elif a==0:
 x1 = -y/(2*x)
 print("x1 = %.2f" % x1)
else:
 print("No roots exist")

 

 

 

Output:

Insert x = 7
Insert y = 8
Insert z = 9
No roots exist

 

Insert x = 4
Insert y = 47
Insert z = 4
x1 = -0.09; x2 = -11.66

Subscribe For Daily Updates