Stuck again on this random.randint exercise
Can any one help on this task, i've been stuck on this for the past hour.
Not sure if my code is even close to the solution.
import random def random_item(name): letter = random.randint(0,len(name)-1) return letter(name) # EXAMPLE # random_item("Treehouse") # The randomly selected number is 4. # The return value would be "h"
Jennifer NordellTreehouse Staff
Hi there! You're pretty close. You've chosen (for some reason) to assign an integer to the variable named
letter. The iterable being passed in you've chosen to name
name. If we then want to get the value at the position (the number named
name and return it, we would do it like this:
So if your function got the random integer 4 and we passed in the word "Treehouse", your code would return "h". That is the value at the index of 4 in the string.
Hope this helps!