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 trialdarren1515
12,031 PointsPython bug in code challenge or am I losing my mind?
Hi
I am trying to answer the below question: 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 my answer
import random
def random_member(input_list):
mynum=random.randint[0,len(input_list)-1]
return input_list[mynum]
It appears that what ever I type, I get a message saying Task 1 is no longer working, which implies the import no longer works.
Am I doing anything obviously wrong?
Thanks
2 Answers
Charlie Thomas
40,856 PointsFirstly make sure your mynum line is on a new line and that both your mynum line and return line are indented by 4 spaces. Secondly change the square brackets [] to normal brackets (). Your code should look like this:
import random
def random_member(input_list):
mynum=random.randint(0,len(input_list)-1)
return input_list[mynum]
darren1515
12,031 PointsThank you, all working now! Changing the square brackets to () fixed it.