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

Daniel Adari
Daniel Adari
3,577 Points

Help in Hit Points challenge!

I have tried solving it in this way with no success... I know there is an easier way but I want to complete it this way... Please help :(

# 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
    nx = x + x_move
    ny = y + y_move

    if (nx) in range(0, 9):
        x = nx
    elif nx > 9:
        hp -= 5
        x = 9
        x = 0

    if (ny) in range(0, 9):
        y = ny
    elif ny > 9
        hp -= 5
        y = 9
        y = 0

    return x, y, hp

3 Answers

Oszkár Fehér
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

Hi Daniel Adari. Actually, you are closer than you may think :smile: , your approach it's good and it works just fine, double check the second elif statement, something it's missing from the end. Happy coding.

Good spot, too!! :smile: :+1:

Hi Daniel,

I had another look at this one to remind myself how this challenge worked.

I did the same as you and created two more variables to represent the x and y change. I then tested whether x plus the change in x position was either less than zero or greater than 9. If so, do nothing to x but take 5 off hp otherwise, allow the change in the else part of the conditional test. Then do the same with y.

I hope that makes sense.


Hi Daniel,

You need to test for scenarios where x or y may become less than zero; not just greater than 9.

I hope that helps a little! Else, get back to me and I'll explain further ... post any new code, though.