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 Hit points

Ollie Webster
Ollie Webster
5,035 Points

I am not getting the right movement results!

Apparently this is not passing because I am not getting the right movement results. The hp decrement works fine when the player crashes, and the movement results seem fine in a separate workspaces window. Any suggestions?

The only thing I can think of is if it wants me to move the x or y even if only the other one would cause a crash. i.e. trying to move in direction (-1, 1) from position (0, 0). Should this not move at all or just permit the y move to 1?

# move((1, 1, 10), (-1, 0)) => (0, 1, 10)
# move((0, 1, 10), (-1, 0)) => (0, 1, 5)
# move((0, 9, 5), (0, 1)) => (0, 9, 0)

def move(player, direction):
    x, y, hp = player
    x_move, y_move = direction
    if not (0 <= x + x_move <= 9) or (0 <= y + y_move <= 9):
        hp = hp - 5
        x = x + x_move
        y = y + y_move
    return x, y, hp

1 Answer

Steven Parker
Steven Parker
220,925 Points

In programming, comparisons must be done individually and combined with logical operators, so where an expression like this might make sense in mathematics:

   (0 <= x + x_move <= 9)

the program equivalent would be:

    (0 <= x + x_move and x + x_move <= 9)

Also, it might help make things less complicated and reduce the chance for errors if you restate the comparisons so you don't need to use "not". For example: "not a <= b" is the same thing as just "a > b"