Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Conor McCracken718 Points
Python Basics: Letter Game Challenge 1 I do not understand why my code doesn't work.
I cannot figure out what is wrong with my code. I am currently getting a Name Error saying my function's name is not defined. Help?
# EXAMPLE # random_item("Treehouse") # The randomly selected number is 4. # The return value would be "h" import random def random_item(iterable): random_index = random.randint(0, len(iterable) - 1) return(index(random_index))
Domenic Carobine9,014 Points
Hey, I think the NameError is coming from "index" in your return statement. Also, you need brackets  to index a string. If you switch up your return statement like I have below you should be able to pass the quiz:
import random def random_item(iterable): random_index = random.randint(0, len(iterable) - 1) return iterable[random_index]