 # NameError: name 'x1' is not defined

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

a,b,c= input("Insert coefficients a, b, and c").split()
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")
``````

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!

X1 and x2 are defined in quadratic_equation and returned. quadratic_equation_user_input cannot see X1 and x2 because they exist only in quadratic_equation. They way you use then is by storing the return of quadratic_equation into variables, you then use those variables to get the expected values for X1 and x2.

thank you!
I understand it.
But how can I really solve it?
(maybe I didn’t understand your last line)

Through standard assignment.

``````def return_sonething():
return 10, 11

a, b = return_something()
``````

In that example a will equal 10 and b will equal 11.

Thank you. sorry about the basic question.