Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JUNPEN gai
687 PointsGuess game implement in 2.7 or 3.6
import random words=['apple', 'banana', 'orange', 'melon', 'lemon', 'pear', 'berry', 'tree', 'dish',] while True: start=input("enter or q ")
This is the code i wrote I find that in 2.7 this not gonna work but not 3.6.
Traceback (most recent call last): File "guess.py", line 13, in <module> start=input("enter or q ") File "<string>", line 1, in <module>
NameError: name 'a' is not defined
line 13 is the last line of the code I show above. Here is the report of 2.7 python, whenever i input a letter this will come out. But in 3.6 this code works. Anyone know what is the difference that makes this happen?
1 Answer

andren
28,520 PointsAll Python courses on Treehouse teaches Python 3. So the project is definitively intended for Python 3.
There are two things in the project that causes issues for Python 2:
The use of
print
as a function. For exampleprint('_', end='')
. In Python 2print
is not a function, but a statement. As such it cannot be passed arguments in the way shown in that code snippet. You could get around this issue by importing Python 3's version ofprint
by including this at the beginning of your Python file:from __future__ import print_function
.The use of
input
. In Python 2 input from theinput
function is evaluated as Python code. To get input as a string you have to useraw_input
instead.raw_input
was renamed toinput
in Python 3 hence why that line works in Python 3.

JUNPEN gai
687 PointsThank you sincerely.
JUNPEN gai
687 PointsJUNPEN gai
687 PointsSorry, I don't know code looks like this in this page.