Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

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))
        break
    else:
        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

python
import random

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