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!

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


Laurynas Stoma
Laurynas Stoma
8,579 Points

not importing 'random' library

Hello, so I get an error that from what I understand it does not import the library

Traceback (most recent call last):
File "random_number.py", line 1, in <module>
import random
File "/home/treehouse/workspace/random.py", line 3, in <module> secret_number = random.randint (1, 10)
AttributeError: module 'random' has no attribute 'randint'

My code:

import random

random_number = random.randint(1, 10)

while True:
    number_guess = int(input("Guess the number between 1 and 10"))
    if number_guess == number:
        print("You are correct! The number is {}".format(random_number))
        print("Try again...")

2 Answers

Huh, weird one, Try reloading the workspace? Your import and random.randint are fine.

Laurynas Stoma
Laurynas Stoma
8,579 Points

Still does the same. Reloading and creating a new file does not help either.

Strange... I can create a new workspace, paste in your code and it works fine (name error on the if statement).

Try just opening a new python workspace and in the command line area at the bottom just type

import random

And see if it works? If not, there's something wrong with yourenvironment - contact support.