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

Andy Hitchings
3,351 PointsHi - what is the answer for this please? I am stuck. Thanks,
Python Basics - code challenge task2/2 - imports.py
5 Answers

Winnie E Tibingana
21,066 PointsHi Andy,
For challenge two please ensure:
- The function has to take a list as argument.
- Create the list with some data say *my_list *
- Create the random numbers using random.randint
- Return the number
As shown below:
Ā
import random
my_list=[1,2,3] #thanks for correct Jason
def random_member(my_list):
random_num = random.randint(0,(len(my_list)-1))
return my_list[random_num]
Hope this helps

Trina Jiroux
22,137 Pointsimport random
def random_num(num):
return random.randint(1, num)

David Myers
895 PointsThank you, Trina.

MUZ140890 David Duri
2,613 Pointsits not passing

Argzon Haziraj
Courses Plus Student 14,994 PointsWinnie E Tibingana can't seem to work that code !!

Jason Anello
Courses Plus Student 94,610 PointsHi Argzon,
You can post the code you're trying if you're still stuck.

Jason Anello
Courses Plus Student 94,610 PointsI decided to recheck the challenge.
I'm not sure if the challenge was changed since this question was asked but the instructions no longer match up with the "best answer" here. Post your current code if you still need help. The solution now is different from what Winnie has posted.

Argzon Haziraj
Courses Plus Student 14,994 PointsThank you Jason Anello But found the problem and i passed the challenge

Andy Hitchings
3,351 PointsFantastic - thank you Winnie & Jason
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsThis passes the challenge but it does not seem like it should.
You're reassigning a new list to
my_list
and losing whatever list was passed in.