0

I'll try to be as quick as possible. I'm working with a while loop in a function, which I simplified here:

def function():
    variable = input("Prompt ")
    while True:
        if variable == "x" or "xx":
            other_var = input("Other prompt ")
        elif variable == "y" or "yy":
            quit()
        else:
            variable = input("Yet another prompt ")
    return other_var

My problem is that the code always acts as if the prompt given was "x" or "xx" no matter what prompt I gave it.

I've tried to make the code run on its own separately from the rest of the program, I've tried to remove completely the "other_var" references and put them outside of the function, and that wasn't the cause, for some reason it simply doesn't acknowledge the existence of the other possibilities.

I have no clue of how to solve it and I'm pretty much a beginner, any help would be appreciated. If more details are needed feel free to ask.

  • 1
    What you have is `(variable == "x") or "xx"`. What you want is `variable == "x" or variable == "xx"`. – paddy Mar 08 '22 at 01:13
  • Thank you, that was the problem, it's just weird cause I've been in a similar situation before but I didn't make this error last time, anyway, it works like a charm now. – Vito Palmieri Mar 08 '22 at 01:18

0 Answers0