Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Taylor HulsmansPython 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
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
William LiCourses Plus Student 26,867 Points
- 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.