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 trialAnthony Kimberly
11,049 Pointsdidn'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
# 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
Steve Hunter
57,712 PointsHi 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
11,049 PointsSteve, THANK YOU! That worked great.
It is always the little things, isn't it? I'll have to hone my attention to detail.
Steve Hunter
57,712 PointsIt 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!