I'm guessing you're talking about an IDE inspection, not an actual runtime error? Are you using an IDE like PyCharm? If so, local variable ... value not used means that you are storing a value (input(...)) in a variable (user_answer) and then you're never using that value. But that is just as it should be, because it seems your program ends there; nothing is using the new value of user_answer.
Just ignore the warning and continue writing your program, making sure to use the new value of the variable, and the warning should disappear.
For context, the purpose of this warning is to catch programming mistakes early on. Suppose that I wanted to write a function that takes a list and appends the element in the middle to either end (front and back), and I wrote this:
def wrap_with_middle_element(sequence):
mid = sequence[len(sequence)//2]
sequence.append(element)
sequence.insert(0, element)
return sequence
You'll notice I didn't actually use the variable mid after defining it, but rather I used element. This could be because, for example, there is a global variable named element which the IDE suggested as code completion and I accepted absentmindedly, or because mid was previously named element, and in manually renaming it to mid (instead of using the IDE's functionality), I forgot to rename the other two appearances of the variable. (I know this seems kind of unlikely, but it's just to illustrate.) In this case the IDE will show the warning: Local variable 'mid': value is not used, since I'm defining mid but never using it. I'd quickly realise what was wrong and fix that (instead of finding out later when running the program).
Working example of OP's code
def my_function():
user_answer = input("Would you like to play a game? ")
while user answer not in ('yes', 'no'):
user_answer = input("Please, answer with yes or no. ")
if user_answer == "yes":
print("Great! I have a number in my head from 1 to 10. Make a guess!")
elif user_answer == "no":
print("Oh, okay! Maybe next time? ")
my_function()
In this example, first we get the user input with user_answer = input("Would you like to play a game? ") and then we make sure that it's either "yes" or "no" with the loop
while user_answer not in ('yes', 'no'):
user_answer = input("Please, answer with yes or no. ")
which terminates only when user_answer in ('yes', 'no') (or, equivalently user_answer == 'yes' or user_answer == 'no') evaluates to True.
Then you can continue with the rest of the program!
# if user_input...
Why it didn't work
With your previous code, the else statement executed when the user didn't input a valid answer (yes or no). But the problem was that, once the user inputted a new value (which could have also been invalid!), the program had nowhere to go (it had already "left behind" the if user_answer == "yes": print(...) code!).
user_answeranywhere beyond this point.