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

I have a trouble with a list..

In this task , this function takes a list and int number and it returns a list... My question is, what does the first list does? i mean..if the return is a list with a max of numbers, why we need it if we can create a list with random inside the function?

if somebody can explain it me better I will be able to reach the challenge :)

Thanks! Alex

choices.py
import random

def nchoices(llista, num):
  items = random.choice()

3 Answers

import random

def nchoices(llista, num):

what you should do in the function body is

  • first create an empty list to hold the result
  • pick a random number from llista, append it to the result list, keep doing that num times.
  • after that, return the result list as the return value of the function.

ok! so, llista have the random numbers.

Thanks William! :)

alex, pick a random number from llista by doing this

random.choice(llista)

That will return you 1 randomly picked element from llista

i did it same than this way, thanks :)