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

Really stuck on this one?

I have been working on this for a while.

item.py
import random

def random_item(argue):
  for argue in random_item:
    return random.randint(0, len(argue) -1) 
return argue.index(

1 Answer

py lund
py lund
1,477 Points

Hey Makan,

There's no need to iterate through the iterable using the for loop. Check this out:

import random

def random_item(argue):
    random_number = random.randint(0, len(argue)-1) 
    """You need to pass two integers to randint. The beginning and the end of the range. 
         In this case, the end is the length of your iterable minus one"""

    return argue[random_number] 
    """Use random_number as index to "retrieve" the corresponding item from your iterable."""