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 trialLuis Bonilla II
11,481 PointsWhy do I get this error when running the program in mac's terminal?
Traceback (most recent call last):
File "number_game.py", line 35, in <module>
game()
File "number_game.py", line 28, in game
play_again = input("Do you want to play again? Y/n: ")
File "<string>", line 1, in <module>
NameError: name 'n' is not defined
4 Answers
Alex Koumparos
Python Development Techdegree Student 36,887 PointsHi Luis,
Thanks for posting your code.
What version of Python are you using (type python3 --version
)?
Also, assuming you are using Python 3 (which you should be, Python 2 is very old and will soon be unsupported), you should ignore Joshua's suggestion which only applies to Python 2.
Your program works fine on my Mac (v3.6.0). However, Apple is notorious for using extremely old versions of Python on their systems. Even Apple recommends that you not use the versions they install.
If you're using an old version of Python then you should definitely install a newer version. Kenneth has done a video for installing Python 3.5 with Pip and Venv on the Mac.
Let me know if you have any issues.
Cheers
Alex
Luis Bonilla II
11,481 PointsRunning Python 2.7.10, thought I was running the latest. Thanks!
Joshua Hostetler
12,351 PointsPython's input
is used to read integers. You should use raw_input
if you want to read text (string) from a user.
Luis Bonilla II
11,481 PointsThat did it. I'm just curious why the instructor's code worked in terminal like that. I ran this code with an iOS app called Pythonista and it ran with no issues but I get that error on the mac with mine or the instructor's code.
Alex Koumparos
Python Development Techdegree Student 36,887 PointsHi Luis,
Can you post your actual code?
Luis Bonilla II
11,481 PointsSo I did have the latest python installed just ran the incorrect command (python instead of python3). raw_input gives and error in the latest release of python
Luis Bonilla II
11,481 PointsLuis Bonilla II
11,481 PointsHere is the code ( note I get the same error with the instructors code too):