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! While you're at it, check out some resources Treehouse students have shared here.
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 trialStephen Coyle
838 PointsI keep getting a "Bummer! NameError: name 'random_item' is not defined" error in a challenge
The challenge is https://teamtreehouse.com/library/python-basics/letter-game-app/random-item
The only occurrence of 'random_item' on the page is a default example which is commented out - I removed this but the same error appears. Even after clearing all data from the challenge code box, then attempting to check answer again, the same error is displayed.
# EXAMPLE
# random_item("Treehouse")
# The randomly selected number is 4.
# The return value would be "h"
import random
def random_int(iterable):
random_letter = random.randint(0, len(iterable) - 1)
return iterable[random_letter]
1 Answer
Steven Parker
231,271 PointsIt's not Python that's complaining but the challenge.
The instructions say "create a function named random_item" but your function is named "random_int" instead.
Stephen Coyle
838 PointsStephen Coyle
838 PointsDoh! Nice spot Steven :-) Working now, cheers