0

As you can see in the following, my intention was to close the program once the user types either "x" or "X" and to ask again (loop) if not. Confusingly, the whole program closes anyway once I type anything but "x" or "X".

import sys

while True:
    userAnswer = input("press x or X to exit")

    if userAnswer == "x" or "X":
        sys.exit()

It would be great if someone could explain this to me. Thanks

  • `if userAnswer == "x" or userAnswer == "X": ` This will work you are missing second condition `or "X"` will always be True and it will break the loop – Ikram Khan Niazi Dec 27 '22 at 12:24

0 Answers0