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 trialLaknath Gunathilake
1,860 Pointsnchoices()
I guess I don't seem to understand the question. Any help is greatly appreciated
import random
def nchoices(itr,intg):
itr.append(intg)
return random.choice(itr)
1 Answer
Oti Oritsejafor
3,281 Pointsimport random
def nchoices(itr, intg):
return intg * list(random.choice(itr))
What you have to do get a random item from the iterable "itr", "intg" number of times
E.g nchoices("apple", 3) will get a random item from "apple" 3 times, so the output could be something like "pae" or "alp"