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 trial

Python Python Collections (Retired) Dungeon Game Random Choices

Taylor Hulsmans
seal-mask
.a{fill-rule:evenodd;}techdegree
Taylor Hulsmans
Python Web Development Techdegree Student 9,563 Points

receiving a syntax error on line 5

not sure why I can't make a while loop this way

choices.py
import random       #need random library
def nchoices(iterable, integer):        #the function with iterable and integer
    random_choices = []             #empty list for output
    count = 0                       #count for while loop
    While count <= integer:          # loop until count exceeds integer
        a_choice = random.choice(iterable)      # an element for our output is a random choice from our iterable
        random_choices.extend(a_choice)         #extend our output with our random element
        count += 1                              # iterate loop
    return random_choices                       # return output

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hi there.

  • Line 5, While is a typo, it's supposed be while all lowercase.
  • LIne 7, .extend() isn't the right method call for the job, as it takes an iterable as its argument, but a_choice is a number not iterable, you should use .append() here instead.