random number from interable?
i'm lost, i get lost with these challenges and that worries me because i get the course work but i get lost on the challenges.. im not sure what to do here?
# EXAMPLE # random_item("Treehouse") # The randomly selected number is 4. # The return value would be "h" import random def random_item(iterable) random.randint(len(interable - 0 -= 1) return(index)
Craig DennisTreehouse Teacher
I see two problems. The term is
iterable as in able to iterate. I see a place where you have misspelled that.
What is happening with the line
return(index) What is index there?
I think you want
len(iterable) - 1.
Let me know if those hints don't help get you heading in the right direction.
You got this!
Jonathan Beard1,681 Points
import random my_list = ['1', '2', '3', '4', '5', '6'] def random_item(x): num = random.randint(0, (len(x) - 1)) return x[num] random_item(my_list)