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 trialBenjamin Bradshaw
3,208 PointsWhat am I doing wrong?
it just keeps saying "try again" so no help there. i tried with a -1 after len(blue) but because the index starts at zero I'm sure that's not what i am missing.
import random
def random_item (blue):
red = random.randint(0,len(blue)
return blue.index(red)
1 Answer
Unsubscribed User
16,600 PointsYou're close, but a few issues:
1) you need to subtract one from the length of your iterable as instructed in the challenge to get the correct index. 2) the challenge wants you to call an index with [] instead of the index() method on the list
import random
def random_item (blue):
red = random.randint(0, (len(blue) -1))
return blue[red]