0

I'm trying to make several branches, and this keeps giving me this name error

I tried deleting the problems it gave me, and then I figured I was deleting the whole thing

while True:
    d1a = input ("Do you want to: A) Approach the house. B) Approach the stable. [A/B]? : ")
    # check if d1a is equal to one of the strings, specified in the list
    if d1a in ['A', 'B']:
        # if it was equal - break from the while loop
        break
if d1a == "A": 
    print ("You approach the cottage.") 
elif d1a == "B": 
    print ("You approach the stables.")

Errors: Traceback (most recent call last): File "main.py", line 5, in d1a = input ("Do you want to: A) Approach the house. B) Approach the stable. [A/B]? : ") File "", line 1, in NameError: name 'A' is not defined

Lucas Urban
  • 627
  • 4
  • 15

1 Answers1

2

It seems you are running Python 2, also called legacy Python. In that version of Python, input tries to evaluate the input. You input A so Python tried to find its value. There was no variable named A so you got the error message.

Use raw_input instead of input. Or better yet, move to Python 3. Your code works fine in my Python 3.7.3.

Rory Daulton
  • 21,934
  • 6
  • 42
  • 50