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

Todd Bascombe
seal-mask
.a{fill-rule:evenodd;}techdegree
Todd Bascombe
Full Stack JavaScript Techdegree Student 11,133 Points

I need help

where did I go wrong ?

item.py
# EXAMPLE
# random_item("Treehouse")
# The randomly selected number is 4.
# The return value would be "h"

import random

def random_item(List):

    li = random.randint(0, len(List) - 1)
    return li

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

You are very close! Instead of return the random index generated, use the index li to select an item from List:

return List[li]

Also, the preferred style is to use lowercase parameter names and to avoid using built-in keywords and types as variable or parameter names. Try lst or arg or item, etc. instead.

Gregorio Bernabel
Gregorio Bernabel
3,412 Points

the challenge is giving you the error Didn't get a correct option back from random_item. I did return the iterable with the variable and it worked. Therefore you are returning the iterable with the randomly selected number

return List[li]