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 trialdaviddavis3
4,904 Pointschoices: bummer or bummer or bummer
I don't see why this code is not working.
import random
def nchoices(iters, n):
random_choice_list = []
i = 1
for i in n:
random_choice = random.choice(iters)
random_choice_list.append(random_choice)
return random_choice_list
2 Answers
Brian Fuller
6,699 PointsDid you mean to say "for i in range(n):" ?
If so, you don't need i = 1 before that. The range function creates a list of numbers for you, which you can then iterate over in your for loop.
daviddavis3
4,904 PointsThat's it! All I needed was to change the n to range(n). Thanks.