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 trialdanielplaisimnd
6,837 Pointspython
Now make a function named random_num that takes an int argument. Return a randint between 1 and the passed-in number. please help
my code
def random_num()
a_list = [1, 2, 3, 4, 5]
num = randint(0, len(a_list))
a_list[num]
1 Answer
Luke Glazebrook
13,564 PointsHi Daniel!
It appears that you have made this too complex!
Take a look at my solution below:
import random
def random_num(num):
randNum = random.randint(1, num)
return randNum
Instead of using a list like you have you can simply just use an integer!
Hope this helps.
-Luke
danielplaisimnd
6,837 Pointsdanielplaisimnd
6,837 PointsThank you