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

Kelley Kent
Kelley Kent
33,450 Points

Imports Code Challenge help needed!

I can't seem to figure this out. I have tried several different things and I'm not sure what i'm doing wrong. Can anyone help!?

Python-Code Challenge: Imports-Challenge Task 2 of 2: Now, make a function named random_member that takes a list. It should generate a random number between zero and the length of the list (minus one), and return the list item at that index.

Here is what I have:

import random

def random_member(a_list):
a_list=[1,2,3,4,5]
random_num = randint(0,(len(a_list)-1))
return a_list[random_num]

2 Answers

Kelley Kent
Kelley Kent
33,450 Points

Oh, never mind! I figured it out...I wasn't indenting, which was affecting my answer...also didn't use random.randint (but I did have that previously when I wasn't indenting)

Thanks anyways!