Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Letter Game App Random Item

Ok this one confused me. I think I may be correct up until the 3rd line of code

Is it my 3rd line of code?

item.py
def random_item("treehouse"):
  x=random.randint(0,len(random_item))-1
    return X[]

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

2 Answers

Steven Parker
Steven Parker
221,451 Points

You have some issues on each line, here's a few hints:

  • the example shows you how the function might be called, not defined
  • when defining a function, the argument name will not be in quotes
  • the argument is the item you will need to take the length of
  • the argument is also the item you will return an indexed element from
  • you will need to subtract one from the length, not the returned random number
  • you will use the random number as the index value in the return statement

I'm betting you can fix it now without an explicit spoiler, but ask again if you still have trouble. You might also want to review the video just prior to the challenge.

Thanks for the direction as oppose to the answer.....that's very appreciated and helpful!!!