Alexandra CiorraPython Web Development Techdegree Student 796 Points
What am I missing?
import random def random_item('Treehouse'): num = random.randint(0, len('Treehouse') -1) return num.index('Treehouse') # The randomly selected number is 4. # The return value would be "h"
Steven Parker170,448 Points
You should not put quotes around variable names. Doing that creates a string literal that represents the name itself instead of the variable's value.
Also, you won't want to use the "index" method here, that's a string method that performs a search and returns an index. Since you have an index already in "num", you just need to apply it to the iterable using bracket notation to get a specific item.
I'll bet you can get it now without an explicit code spoiler.
Ben HedgepethPython Web Development Techdegree Student 6,148 Points
For the challenge you don't necessarily need to pass in an argument. What is required is writing a function definition that can take any applicable iterable and have the function apply some work to it in the function body and return a value.
For instance, I used
word as the parameter when I did the challenge. It's a semantic placeholder so if anyone reads your code they have an idea of what type of input is provided to the function.
Did you remove all quote marks for all parameters? Did you revise your code as Steven pointed out?