0

I am getting a classic

NameError : name 'Y' is not defined.

I know this is extreme beginner level and a multitude of similar questions have been answered. However none of the answers have helped me fix this simple issue. Replies would be greatly appreciated.

def intro ():

#checks if the user already has an account and redirects accordingly

print("ARE YOU A REGISTERED USER? [Y/N]")
redirect = input()
if redirect == "Y" :
    print("OK")
else :
    print("gtfo")

intro()

linqo
  • 617
  • 4
  • 16
Anton
  • 1
  • Why are you using Python 2? It has reached its end of life and is no longer supported. You need to change to Python 3 and this problem wouldn't exist (in python 2, you need `raw_input` for this) – roganjosh May 01 '20 at 12:35
  • Oh geez i havent checked the version, just started with the one that came with linux when I switched from windows. Thank you very much – Anton May 01 '20 at 12:40
  • It may be as simple as changing `python my_script.py` to `python3 my_script.py` if there is already a Python 3 installation – roganjosh May 01 '20 at 12:42

2 Answers2

0

Looks like you're using Python 2. Try using raw_input() instead of input(). input() on Python 2 is equivalent to eval(raw_input(string)).

linqo
  • 617
  • 4
  • 16
  • https://stackoverflow.com/questions/21122540/input-error-nameerror-name-is-not-defined – AMC May 01 '20 at 13:02
0

this worked for me using python3, you can add a way to also check lower case inputs.

def intro():
    redirect = input("ARE YOU A REGISTERED USER? [Y/N] ")
    if redirect == "Y" :
        print("OK")
    else :
        print("gtfo")


intro()
exit = input("press any key to exit")
yoss
  • 97
  • 9
  • https://stackoverflow.com/questions/21122540/input-error-nameerror-name-is-not-defined – AMC May 01 '20 at 13:02