0

My code looks like this

def title_screen_selections():
  option = input()
  if option.lower() == ("play"):
      start_game()
  if option.lower() == ("help"):
      instruction_menu()
  if option.lower() == ("quit"):
      sys.exit()
  while option.lower() not in ['play', 'help', 'quit']:
      print("Please enter a valid command.")
      option = input("> ")
      if option.lower() == ("play"):
          start_game()
      if option.lower() == ("help"):
          instruction_menu()
      if option.lower() == ("quit"):
          sys.exit()

when I type

python filename.py

into terminal, it displays the title screen. When I try to type play, it gives me

Traceback (most recent call last):
  File "game.py", line 272, in <module>
    title_screen()
  File "game.py", line 270, in title_screen
    title_screen_selections()
  File "game.py", line 218, in title_screen_selections
    option = input()
  File "<string>", line 1, in <module>
NameError: name 'play' is not defined

When I type 'play' with single or double quotes, it works fine. Any suggestions? I'm relatively new to python

  • bash is not related to this issue in any way. It's a problem with using Python 3 code in Python 2. – Charles Duffy Jan 09 '20 at 22:42
  • ...in Python 2, you would need to use `raw_input()` instead of `input()`. But Python 2 is no longer supported; you shouldn't be using it. – Charles Duffy Jan 09 '20 at 22:42
  • You are using Python 2, not Python 3. Don't use Python 2, it is a language that is [officially passed it's end of life](https://pythonclock.org/). – juanpa.arrivillaga Jan 09 '20 at 22:42
  • (when you run a program from your shell without redirecting its stdin, stdout and stderr, that program inherits file descriptors that let it talk straight to the terminal itself, without the shell in the way; thus, when you start `python` from bash, what you type from there until python exits is being read directly terminal->python, not terminal->bash->python -- which is why the "bash requiring me" part of the title is inaccurate, as bash has nothing to do with it and behavior would be identical if you didn't use bash at all). – Charles Duffy Jan 09 '20 at 22:50

0 Answers0