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
160,434 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
160,434 Points

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