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 trial

Python Python Basics (2015) Letter Game App Random Item

Alisa Tashiro
Alisa Tashiro
724 Points

Help with code! NameError Random Item Python Challenge

Still not sure how I attach my code, but this is my code:

import random

def random_item(iterable):
     return iterable[random.randit(0,len(iterable)-1)]

My error is a NameError: name random_item is not defined

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

The error is misleading. random_item isn't found due to a typo. Use randint not randit:

import random

def random_item(iterable):
     return iterable[random.randint(0,len(iterable)-1)]  # <-- use randint
Alisa Tashiro
Alisa Tashiro
724 Points

Oh!! Thank you so much!! It was driving me crazy!