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 Python Basics (2015) Letter Game App Random Item

Benjamin Bradshaw
Benjamin Bradshaw
3,208 Points

What 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.

item.py
import random

def random_item (blue):
    red = random.randint(0,len(blue)
    return blue.index(red)

1 Answer

You'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]