Oddly, this throws an error when I run it in the terminal and press Q, then Enter. The error text is "name 'Q' is not defined". However, if I run it in the debugger in Thonny, it works fine.
Code: Select all
import sys bool_running = True try: while bool_running: str_Choice = input("Choose 1 or Q: ") print(str_Choice) if str_Choice == 'Q': #then we want to Quit print("Quit") bool_running = False sys.exit() elif str_Choice == '1': #then we would do something ''' In Windows 10, this works In Raspian, it has to be without the 's ''' print("You chose: ", str_Choice) else: print("You have to choose 1 or Q") except Exception as e: print(e)
If I use an integer instead of a letter (say, 4), this all works fine.
One curiosity is that if I run it in Windows 10, Python 3.7.8, it works only if the if statements reference string values without quotes (i.e., 1, not '1') but in Raspian the opposite is true.
I must be misunderstanding something but I cannot figure out what that is. What heck am I doing wrong?
Thank you, everyone, and thanks for being patient with me.