Cant understand why this code is not working?
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 index.randint()
# EXAMPLE import random def random_item("iterable"): random.randint(0, len(iterable) - 1) return index.randint() # random_item("Treehouse") # The randomly selected number is 4. # The return value would be "h"
Cameron Nilon15,311 Points
Let's break it down a bit. Remember to index an iterable you can use '' in other words, say you have "hello" and you want to get the letter 'e', you would get this by indexing with square brackets , remember it is zero indexing. Now to use randint() you basically have that correct, except iterable is not defined. randint() returns a number between your first arg and your second arg. Also, I wanted to point out that your parameter is syntactically incorrect, lose the quotations or assign "iterable" to word without quotations ie iterable = "iterable".
Allow me to give you an example on how you can do this challenge.
import random def random_item(arg): return arg[random.randint(0, len(arg)-1)]