Not sure why i'm getting NameError for clinic()


#1
def clinic():
    print ("You've just entered the clinic!")
    print ("Do you take the door on the left or the right?")
    answer = input("Type left or right and hit 'Enter'.").lower()
    if answer == "left" or answer == "l":
        print ("This is the Verbal Abuse Room, you heap of parrot droppings!")
    elif answer == "right" or answer == "r":
        print ("Of course this is the Argument Room, I've told you that already!")
    else:
        print ("You didn't pick left or right! Try again.")
        clinic()

clinic()

Do you take the door on the left or the right?
Type left or right and hit ‘Enter’.l
Traceback (most recent call last):
File “script.py”, line 13, in
clinic()
File “script.py”, line 4, in clinic
answer = input(“Type left or right and hit ‘Enter’.”).lower()
File “”, line 1, in
NameError: name ‘l’ is not defined


#2

input() evaluate the user input as code. if you type l, l will be evaluated as code. Which would be a undefined variable


#3

how would you solve this problem then?
i noticed that when i return “l”, it works.


#4

yea, "l" is evaluated as string, but its quite a security risk, given the user can inject code! surely there must be a better function


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.