0

Python Newbie here (First day learning).

I'm using Python 2 and using the following if statement code:

meaty = input('Do you eat meat? (y/n):')

if meaty == 'y':
    print 'Here is the meaty menu...'
else:
    print 'Here is the veggie menu...'

I get this error:

Traceback (most recent call last):
  File "if_elif.py", line 11, in <module>
    meaty = str(input('Do you eat meat? (y/n):'))
  File "<string>", line 1, in <module>
NameError: name 'y' is not defined

The tutorial I'm following is using Python3 but I'm using Python 2 so maybe that can explain this error?

Thanks guys

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
user8322222
  • 489
  • 3
  • 14
  • 28
  • 1
    Use `raw_input()`, not `input()`, on Python 2. Better still: if you are learning the language, start with Python 3. Python 2 is a legacy release now. – Martijn Pieters Oct 02 '18 at 10:53
  • Thanks that worked!!! The course I'm learning machine learning from is teaching in Python 2.7 that's why I installed 2.7 using Anaconda but I'll definitely start using Python 3 after this course is complete. – user8322222 Oct 02 '18 at 11:16

0 Answers0