Why does it say x isn't defined?
the variable x is defined in the function definition. define it outside the function and take it as a variable in the function: later on call the function with variable x. x = input() def f(var): blablabla f(x)
because you define variable x in function and it is not visible to other function, so you can change x to be global variable
that x is a local variable used inside function
Can I just "return" x?
you can return x if you want to use it in an other function. just try and see what happens. recursion seems the way to go in the code you are writing. call the function within the function if it is a tie.