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 trialDavid McCarty
5,214 Pointsrandom.choice problem giving me trouble
Oddly enough, this code doesn't seem to be working. It keeps just saying "Bummer! Try again" Even though I'm pretty sure this should work. i've tried multiple different ways, but nothings working.
Seems odd as I'm almost entirely sure this should work.
import random
def nchoices(iterable, n):
the_list = list()
for num in n:
the_list.append(random.choice(iterable))
return the_list
1 Answer
Martin Cornejo Saavedra
18,132 PointsI think you can't iterate over an integer 'n', but you can over a range(n):
import random
def nchoices(iterable, n):
the_list = list()
for num in range(n): #here I did a change
the_list.append(random.choice(iterable))
return the_list
David McCarty
5,214 PointsDavid McCarty
5,214 PointsAh yes! You would be correct.
Thanks for the help!