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

Cartographer: I have 2 player "X" on map, not sure why...?

Here is my code, I followed along but I am getting two player locations, not sure why

def draw_map(player):
    print(" _" * 5)
    tile = "|{}"

    for cell in CELLS:
        x, y = cell
        if x < 4:
            line_end = ""
            if cell == player:
                output = tile.format("X")
            else:
                output = tile.format("_")
        else:
            line_end = "\n"
            if cell == player:
                output = tile.format("X|")
            else:
                output = tile.format("_|")
        print(output, end=line_end)

I figured out the issue, I had duplicates/typos in my CELLS tuple, correct list is

CELLS = [(0, 0), (1, 0), (2, 0), (3, 0), (4, 0),
         (0, 1), (1, 1), (2, 1), (3, 1), (4, 1),
         (0, 2), (1, 2), (2, 2), (3, 2), (4, 2),
         (0, 3), (1, 3), (2, 3), (3, 3), (4, 3),
         (0, 4), (1, 4), (2, 4), (3, 4), (4, 4),]
Steven Parker
Steven Parker
241,488 Points

This is a great example of why it's important to include the whole code with a question. Since the CELLS array wasn't originally shown, it would not have been possible for anyone to find the cause of the issue!

1 Answer

Thanks for the re-assurance on that. I felt like I was including too much code but I will keep this in mind in the future to just include all my code

Steven Parker
Steven Parker
241,488 Points

When using the workspaces, you can always include a link to a "snapshot" which contains all the code but doesn't take up any room in the question.