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 (2016, retired 2019) Dungeon Game random.sample


help needed

import random
import os
import sys

CELLS = [(0,0),(1,0),(2,0),(3,0),(4,0),

def clear_screen():
    if os.name == 'nt':
    else: os.system('clear')

def get_locations():
    return random.sample(cells,3)

def move_player(player, move):
    #ascertain current player location
    #if move == LEFT, x-1
    #if move == RIGHT, x+1
    #if move == UP, y-1
    #if move == DOWN, y+1
    return player

def get_move(player):
    move = ["LEFT", "RIGHT", "UP", "DOWN"]
    x, y = player
    if x == 0:
    if x == 4:
    if y == 0:
    if y == 4:
    return move

monster, door, player  = get_locations()

while True:
    print("Welcome to the DUNGEON !")
    print("You are currently in room {}".format(player)) 
    print("You can move {}".format(", ".join(get_move(player))))
    print("Enter QUIT to quit")

    move = input("> ")
    move = move.upper()
    if move == 'QUIT':
        print("I guess you were afraid of the DUNGEON!")

2 Answers

Dane Parchment
Dane Parchment
Treehouse Moderator 11,023 Points

Why do you have all of that extra code? Read the instructions of the challenge:

I haven't shown you how to use this function yet but I'm sure you can use it. In the random library, there's a function named sample that takes two arguments: an iterable to sample from, and an integer of how many unique samples to return. Finish the get_locations function so that it returns 3 unique values from the cells argument.

So simply do what it is asking you to do, in fact you already did it!

def get_locations():
    return random.sample(cells,3)

There done! Just remove all of the extra code that you have written, it is not necessary and will cause the submission to fail!

Copy and pasted all of the code, I'm on the same thing and I don't get all of that code

this worked for me

def get_locations(cells):

return random.sample(cells,3)