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 trialzfusdjitsz
2,797 PointsWhat am I missing on this nchoices() func? I'm pretty sure this code is good - unless I'm misunderstanding the challenge
def nchoices(iterable,integer):
my_list = []
x = 0
while x < integer:
my_list.append(random.choice(iterable))
x += 1
return my_list
zfusdjitsz
2,797 PointsAgreed...I think there may be issues...thanks Ricky
Ricky Catron
13,023 PointsOf course. I tested your solution and then one of my own and both threw the same error.
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi Kurt,
You have to import the random module in order to use random.choices()
As far as I know, the code challenges don't import modules for you.
Ricky Catron
13,023 PointsFace meets desk should have seen that.
Jason Anello
Courses Plus Student 94,610 PointsWell, I think the error message throws you off.
Ricky Catron
13,023 PointsIt does, why are the error messages so vague? Any unix console would have returned a far better error.
Kenneth Love
Treehouse Guest TeacherThat's because, like a dummy, I only assumed the NameError
would come from the student not creating nchoices
. I'll update it.
zfusdjitsz
2,797 PointsThanks Jason Anello . Good catch
Jason Anello
Courses Plus Student 94,610 PointsYou're welcome, Kurt.
Thanks Kenneth. The new error message should lead people in the right direction.
Ricky Catron
13,023 PointsRicky Catron
13,023 PointsYour solution looks fine to me it is possible that the question/site is having problems.