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

Python Python Basics (Retired) Pick a Number! Any Number! Imports

After adding a the requested function I'm getting prompted that the original import statement is no longer passing.

I've not changed any thing in my the import statement, so I'm not sure why the test on the import statement is no longer passing?

random_num.py
# import statement
import random

# function
def random_num(x):
  return randint(1, x)

2 Answers

Max Hirsh
Max Hirsh
16,773 Points

Hey Carl. Sometimes the first task stops passing if there's some issue with a function later in the code. Your answer looks good, but remember that randint is a method of the random library. Library methods have to be called like this: library.method()

Hope this helps!

Thanks ... I actually figured it out after testing it locally. It throws a more informative error. Normally I'd be more specific on something this small and do something like this:

from random import randint

def random_num(x):
    return randint(1, x)

print(random_num(5))

But thanks for the quick response.

Max Hirsh
Max Hirsh
16,773 Points

Oh ok! Glad you figured it out/sorry for inadvertently answering a question you already solved. But yes, you definitely have the right idea with only importing a specific function.