Logan ValdezPro Student 4,384 Points
Not Quite Sure What To Do. (Letter Game App challenge)
Hello. With this challenge I am supposed to return the iterable member that is at my random number’s index, however I am receiving an error with my code and I am not sure how to remedy this issue.
# EXAMPLE # random_item("Treehouse") # The randomly selected number is 4. # The return value would be "h" import random def random_item(a): random.randint(0, len(a)) - 1 return a
Zachary JacksonTreehouse Project Reviewer
There are two things you need to fix to get this challenge working. The first is that the item you are getting in the function 'a' is the same thing you are returning. You have not done anything to 'a'. What this project is wanting is a random index from 'a' on the return statement.
You have gotten a random index with
random.randint(0, len(a)) - 1. This is the correct way to get a random index. Good work. Now you just need to store the random index in a variable and use it in the return statement to return a random index from 'a'.
I will let you put the pieces together to make your function work. If you have any issues or questions about anything let me know.
I'm also lost on this one. I've tried several iterations and can't figure out exactly what I'm missing.
import random word = ("Potatoes") def random_item(word): rand = random.randint(0, len(word)) - 1 return rand
import random number = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] def random_item(number): rand = random.randint(0, len(number)) - 1 return number.index(rand)