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 trialhenry hui
2,698 PointsWhen 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
231,248 PointsNeither 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
2,698 Pointshenry hui
2,698 PointsThanks 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
231,248 PointsSteven Parker
231,248 PointsThere's no difference other than the name itself. As I said, both work for me after correction.