Welcome to the Treehouse Community
Looking to learn something new?
Alexandra Montgomery520 Points
Isn't this right?
You've seen how random.choice() works. It gets a random member from an iterable (like a list or a string). I want you to try and reproduce it yourself. First, import the random library. Then create a function named random_item that takes a single argument, an iterable. Then use random.randint() to get a random number between 0 and the length of the iterable, minus one. Return the iterable member that's at your random number's index. Check the file for an example.
input random def random_item(iterable): return iterable [random.randint(0,len(iterable)-1) ]
Jason AndersTreehouse Moderator 145,692 Points
Hey Alexandra. Welcome to Treehouse.
It is correct except for one thing. You want to
import random ... not
input. The rest of the code is correct, so just change that one thing and you're good to go.
Keep Coding! :)