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 trialJim Garman
Python Web Development Techdegree Student 1,716 Pointsrandom.randint ERRORs
I'm having trouble with the random.randint module. I'm sure it's something dumb I'm doing but I can't get this simple program to run:
import random
print(random.randint(1, 10))
I get the following error message:
Traceback (most recent call last):
File "temp.py", line 3, in <module>
print(random.randint(1, 10))
AttributeError: module 'random' has no attribute 'randint'
Then, I went back to our number game program and tried to run it again and got the same error message. I know this game used to run without errors. Maybe there is an issue importing the random module?
Please help, I'm completely stuck on my code challenge. Tks JG
2 Answers
Steven Parker
231,236 PointsIt certainly looks like it should work.
If this is for a workspace, you could make a snapshot of your workspace and post the link to it here for analysis.
If this is from a locally-installed version of python, your library may have gotten damaged. It might make sense to re-install.
Jim Garman
Python Web Development Techdegree Student 1,716 PointsBrilliant! Thank you. I figured it was something weird I was doing.
Jim Garman
Python Web Development Techdegree Student 1,716 PointsJim Garman
Python Web Development Techdegree Student 1,716 PointsWow! I've never done a snapshot before. So cool. Here is my snapshot. The simple script is filed as: temp.py . There is also the number_game.py program that is not working anymore also. Thanks for checking it out.
https://w.trhou.se/d4r5ymc2rp
Steven Parker
231,236 PointsSteven Parker
231,236 PointsNow that I see your workspace, I notice that you have a local file named random.py. So when you "
import random
" that file is being loaded instead of the Python library file.Just give that file another name and the problem will go away.