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 trialmohit jain
1,060 PointsThis code does the work but still is not accepted by the console
I have run this in the console and it seems to work but why doesn't treehouse accept it?
def nchoices(n,itr):
count=0
my_list=[]
while count < n:
my_list.append(random.choice(itr))
count=count+1
return my_list
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsYou are very close. The challenge says " a function named nchoices() that takes an iterable and an integer". Order is important on the parameters and should match the order in the task description Your parameters were reversed. Also, you need to import random
:
import random
def nchoices(itr, n):
count=0
my_list=[]
while count < n:
my_list.append(random.choice(itr))
count=count+1
return my_list