Python Python Collections Dungeon Game random.sample

Mathew Yangang
Mathew Yangang
Python Web Development Techdegree Student 2,456 Points

random.sample

I keep getting couldn't find get locations errors

sample.py
import random


def get_locations(cells):
    random.sample(x,y)

    pass

    return get_locations()
    return get_locations()
    return get_locations()

1 Answer

Dave Harker
Dave Harker
Front End Web Development Techdegree Student 10,501 Points

Hi Mathew Yangang,

You can only process a single return from a function but I can see what you were trying to achieve there. Since that isn't an option however we can use the random.sample function from Python random, which returns a list.

From the python documentation found here: Python 3 - Random

random.sample(population, k)
Return a k length list of unique elements chosen from the population sequence or set. Used for random sampling without replacement.

So with that in mind, you could try something like:

return random.sample(cells, 3)

Keep on coding!
Dave :dizzy:

P.S. You can just delete that pass from the challenge ... not sure why they put that there.