hi friends.
I’m tring to figure out a quadratic equation, by using another function.
But when I tried calling the first function, I got an error:
def quadratic_equation(a, b, c):
import math
d = int(b) ** 2 - 4 * int(a) * int(c)
if d < 0:
x1 = None
x2 = None
elif d == 0:
x1 = (-1 *int(b) + math.sqrt(int (b) ** 2 - 4 * int(a) * int(c))) / 2 * int(a)
x2 = None
else:
x1 = (-1 * int(b) + math.sqrt(int(b) ** 2 - 4 * int(a) * int(c))) / 2 * int(a)
x2 = (-1 *int(b) - math.sqrt(int (b) ** 2 - 4 * int(a) * int(c))) / 2 * int(a)
return x1, x2
def quadratic_equation_user_input():
a,b,c= input("Insert coefficients a, b, and c").split()
quadratic_equation(a, b, c)
if a==0:
print("The parameter 'a' may not equal 0")
else:
if x1!=None and x2!=None :
print("The has 2 solutions:", x1, "and", x2)
elif x2 == None:
print("The equation has 1 solutions:", x1)
elif (x1 and x2) == None:
print("The equation has no solutions")
quadratic_equation_user_input()
this is the error:
if x1!=None and x2!=None :
NameError: name ‘x1’ is not defined
I don’t know how I can fix it.
thank you!