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

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
231,236 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!!!