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

henry hui
henry hui
2,698 Points

When i input def random_item(iterable): it shows NameError: name 'iterable' is not defined

When i input

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

it shows NameError: name 'iterable' is not defined

But wen i input

import random
def random_item(iterable_thing):
    return iterable_thing[random.randint(0,len(iterable_thing)-1)]

it is correct

What is the different between "iterable" & "iterable_thing"?

1 Answer

Steven Parker
Steven Parker
229,657 Points

Neither one of those works for me (but I get a different error message).

But both will work if you change "randint" to "random.randint", or if you change "import random" into "from random import randint".

henry hui
henry hui
2,698 Points

Thanks Steven,

Its Typing error.. i add back the random now,

the one with (iterable) Shows -- "NameError: name 'iterable' is not defined" and the one with (iterable_thing) -- "Correct"

Whats the different with iterable and iterable_thing..?

Steven Parker
Steven Parker
229,657 Points

There's no difference other than the name itself. As I said, both work for me after correction.