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 trialBen Muresan
589 PointsCalling a random num?
It says that I didn't create a "random_num" function but I think I did. Whats up here?
import random
def random_num(num):
y = randint(1,num)
return y
2 Answers
Andrew K
13,774 PointsHi Ben, You either need to specify what you are importing from the "random" module initially (from random import randint), or else specify the module when calling the randint function. So:
import random
def random_num(num):
y = random.randint(1,num)
return y
That should do it! (Worked for my test at least)
Clayton Perszyk
Treehouse Moderator 48,850 PointsHey Ben
When you import a module, you need to use the module's name to access any of its methods. For example, if you have a module named math and you want to call the add method, you would need code that looks something like this:
import math
def num_plus_two(num):
return math.add(2, num)
jack hamilton
5,609 Pointsjack hamilton
5,609 PointsI just attempted it as well not working for either.