Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Lynda Montgomery
766 PointsCode not working in terminal
Hey! My code isn't working in terminal but it runs in the workspace, any tips?
import random
words = [
'melon',
'Lemon',
'berry',
'blueberry',
'strawberry',
'apple',
'banana',
'lime',
'grapefruit'
]
while True:
start = input('Press enter to start or enter Q to quit. \n')
if start.lower() == 'q':
break
else:
print('Have fun!')
Ryan S
27,276 PointsHi Lynda,
What is the error you are getting?
1 Answer
Alexander Davison
65,469 PointsIf you type python --version in the Console (or Terminal, Command Prompt, etc), you get the version of Python.
On Treehouse Workspaces it will return "3.x.x" where the X's are other numbers, in your console by default will return "2.x.x".
Python 2 (your computer's defualt) and Python 3 (Workspace's default) are pretty different.
Main differences are listed here:
- Python 2 has
printas a keyword, not a function. This means in Python 2 your would print without parentheses and in Python 3 will need parentheses.
Examples:
# Valid in Python 3
print("Hello")
# Valid in Python 2
print "Hello"
The very important difference that confuses lots of beginners is the
inputfunction. In Python 3 by default it turns the input into a string. If you type in something into your program in this example "hello", Python 2 actually will look for a variable calledhello.And there are many more differences.
So about that second difference I listed, it important.
To fix your problem, either use the function raw_input instead of input or install Python 3 and type in:
python3 your_file.py
instead of:
python your_file.py
Try doing either of those :)
Good luck! ~alex
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 Pointsfixed code formatting