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.

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"