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

Laknath Gunathilake
Laknath Gunathilake
1,860 Points


I guess I don't seem to understand the question. Any help is greatly appreciated

import random
def nchoices(itr,intg):
    return random.choice(itr)

1 Answer

Oti Oritsejafor
Oti Oritsejafor
3,281 Points
import 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"