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
Andrew Harris
4,235 PointsTraceback on my local Python
I just switched over from running python 2.7 to python 3.4.2, and I am running through the tutorials on here. when I run this code in workspaces it runs fine.
input_string = input("What string do you want to use? ") input_int = input("How many times should I repeat it? ")
print(input_string*int(input_int))
but, when I run it on my local computer (both sublime 2, and notepad ++ text editors) and run it in the CMD line i get this traceback error.
file "<string>", line 1, in <module> NameError: name 'whatever I input here' is not defined.
I am not sure why I am getting this traceback error, as I copy pasted my working code out of name spaces.
1 Answer
Gavin Ralston
28,770 PointsIt seems you're using the python 2.7 interpreter on your command line. Python 2.7 would require those to be raw_input calls instead of input, and will then fuss over the input after you get it.
Check by running python -V at the command line to see the version.
If you run python3 yourfile.py instead of python yourfile.py it'll probably work like you expect.
Not sure what operating system you're using, but some sort of solution will be available to you to fix it. A shebang in your python files, or using pyenv or venv, etc.
Trevor Currie
9,289 PointsYep, check your version! Treehouse uses Python 3.4.
Caleb Kleveter
Treehouse Moderator 37,862 PointsThank Gavin!
Andrew Harris
4,235 PointsAndrew Harris
4,235 PointsThat obviously lost formatting, what string do you want to use line 1; how many times line 2; print line 3