I'm stuck in the random..
I know I'm close, but I can't do it..
# EXAMPLE # random_item("Treehouse") # The randomly selected number is 4. # The return value would be "h" import random def random_item(arg): random_arg = random.randit(0, len(arg)-1) return arg.index(random_arg)
Chris FreemanTreehouse Moderator 58,942 Points
You have right approach. Three errors need fixing.
- typo should be
returnstatement is indented too far. It should align with statement above it.
- to reference the index of a container object use square brackets (also called braces):
Post back if you need more help. Good luck!!!
Thank you again!
import random def random_item(arg): random_arg = random.randint(0, len(arg)-1) return arg[random_arg]