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 Python Collections (2016, retired 2019) Dungeon Game Hit points

Anthony Kimberly
Anthony Kimberly
11,049 Points

didn't get the right movement

Alright, I'm having trouble with this. I'm trying the examples AND getting the correct results but it still says "Bummer! Hmm, didn't get the right movement!"

I am also trying this one locally and running it in Terminal so I can view the print output. It is the same as the code shown below but I've added a print statement to view and verify the output: print("{}, {}, {}".format(x, y, hp))

My output is this:

python playerhitpoints.py 0, 1, 10

0, 1, 5

0, 9, 0

movement.py
# EXAMPLES:
# 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
    xm, ym = direction
    # handle the hit points
    if x + xm < 0 or x + xm > 9:
        hp -= 5
    if y + ym < 0 or y + ym > 9:
        hp -= 5
    # handle the movement
    if (x + xm) >= 0 and (x + xm) <= 9:
        x += xm
    if y + ym > 0 and y + ym < 9:
        y += ym  
    return x, y, hp

2 Answers

Hi Anthony,

Your last if statement should include equal to as well - then your code works fine.

if y + ym >= 0 and y + ym <= 9:

Steve.

Anthony Kimberly
Anthony Kimberly
11,049 Points

Steve, THANK YOU! That worked great.

It is always the little things, isn't it? I'll have to hone my attention to detail.

It is so often a small mistake that you don't see - I've spent days looking at the problem and not seeing it! I try to write tests for my code to catch these errors in a controlled way. I don't know what testing framework would be used for Python; I'm not a Python developer. I'm sure Google will help with that!