Welcome to the Treehouse Community
Looking to learn something new?
Frank SherlottiCourses Plus Student 1,952 Points
Random choices challenge: How do I get my loop to stop at a certain integer?
Create a function named nchoices() that takes an iterable and an integer. The function should return a list of n random items from the iterable where n is the integer. Duplicates are allowed. --- I think my code so far does what it's asking me to do but I just can't quite figure out how to make it stop at a certain spot. Any help would be greatly appreciated. THANKS!
def nchoices(thing, num): x =  import random for item in thing: random.choice(thing) x.append(thing) return x
leong shing chew5,618 Points
def nchoices(thing, num): x =  count=0 import random while (count < num): random.choice(thing) x.append(thing) count = count +1 return x
How about using a while loop rather than a for loop?