Welcome to the Treehouse Community
Looking to learn something new?
Alejandro Byrne2,562 Points
Need help on this challenge. Don't quite understand what to do for the last step.
How do I do the last two steps? I don't get what I'm supposed to do.... or how to do it....
# EXAMPLE # random_item("Treehouse") # The randomly selected number is 4. # The return value would be "h" import random def random_item(iterable): random.randint(0, len(iterable) - 1) return(???)
First since you need to use the random number generated you actually have to store it in a variable, currently you just generate a number but then do nothing with the result. Then you need to pull an item/character out of the iterable you get using the random number as the index. You can do this by using square bracket notation which you should have learned in an earlier part of this course.
As a reminder when using bracket notation to pull out items you just place brackets after the variable name and then the index you want to pull out. So to pull out the first item you would use
iterable for example.
Don't give up! You are doing very well. You already got a random index all set up!
You just have to use that index to get the item in the iterable.
Here's how to get a specific character from a string using an index:
"Treehouse" # Returns "e"
I would recommend to try to do this challenge on your own, but if you keep failing I'd be happy to help more
Good luck! I hope this helps out. ~Alex