pythonif-statementundefined

Python If Statement definition error


I'm trying to test out if statements with the use of letters instead of numbers. I'm not sure what the error in my code is, can someone please help out

ppp=input('Enter a, or b. or exit to exit')

while ppp!='exit':

    if ppp=='a' or ppp=='A':
        print('You Picked A')
        ppp=input('a,b, or c?: ')

    elif ppp=='b' or ppp=='B':
        print('You Picked B')
        ppp==input('a,b, or c?: ')

    else:
        print ('please choose a, or b')

When running it, it prints "Enter a, or b. or exit to exit" but when entering anything whether a, A, b, B, exit, or any random word or letter or number I get

Traceback (most recent call last):
  File "temp.py", line 1, in <module>
   ppp=input('Enter a, or b. or exit to exit')
  File "<string>", line 1, in <module>
NameError: name 'a' is not defined

Please someone tell me what's wrong with my code.


Solution

  • You are using input function in python2, it should be raw_input() instead.

    ppp=raw_input('Enter a, or b. or exit to exit')
    

    Check this answer for more information