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 trialpranjul mishra
4,138 PointsNameError: name 'random_item' is not defined
please explain why it is giving name error
# EXAMPLE
# random_item("Treehouse")
# The randomly selected number is 4.
# The return value would be "h"
import random
def random_item(iterable):
return iterable[random.radint(0,len(iterable)-1)]
1 Answer
andren
28,558 PointsThe error message is misleading. It is caused by the fact that the code checker crashes while trying to run your code. It does that because you have a typo in your code.
You have written random.radint
instead of random.randint
. If you fix that typo then your code will work.
pranjul mishra
4,138 Pointspranjul mishra
4,138 Pointsyeah, just got it. Due to incorrect error message, not able to get the error. Thanks!