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.
Daniel Adari3,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 :(
# 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 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 else: x = 0 if (ny) in range(0, 9): y = ny elif ny > 9 hp -= 5 y = 9 else: y = 0 return x, y, hp
Oszkár FehérTreehouse Project Reviewer
Hi Daniel Adari. Actually, you are closer than you may think , 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.
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
I hope that makes sense.
You need to test for scenarios where
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.