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
Tristan Gaebler
6,204 Points"Import random problem"
I'm currently doing the python challenge of making a number guessing game. I typed "important random" into the terminal "Workspaces" and everything was fine, but when I run my script it says "name 'random' is not defined'. This is my code
''' random.randint(1, 10)
1 Answer
Trevor Currie
9,289 PointsIf you have an open python workspace, you should only have to do the following things: 1.) Start a python shell, by typing 'python' <enter> 2.) Import the random library, by typing 'import random' <enter> 3.) Pick a random integer, by typing 'random.randint(1,10)' <enter>
Alternatively, you can 2.) Import the randint command from random, by typing 'from random import randint' <enter> 3.) Select a random integer, by typing 'randint(1,10)' <enter>
That's all!
Tristan Gaebler
6,204 PointsTristan Gaebler
6,204 PointsAll I had to do is write 'import python' at the top. Thanks for the help!!!!