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

Andrew Cousineau
Andrew Cousineau
17,320 Points

Movement.py doesn't validate in treehouse interpreter. Shell works fine.

I tried running my code in the python shell on my computer which works for the 3 test cases given in the commented examples. However, my code doesn't validate by the treehouse interpreter. Is there a test case I'm not catching or aware of?

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
  directionX, directionY = direction

  if x + directionX < 0 or x + directionX > 9:
    hp -= 5
  if y + directionY < 0 or y + directionY > 9:
    hp -= 5
  if x + directionX > 0 and x + directionX < 9:
    x += directionX
  if y + directionY > 0 and y + directionY < 9:
    y += directionY

  return x, y, hp

1 Answer

Steven Parker
Steven Parker
231,269 Points

You're not allowing movement up to the edge.

When you check for legal movement, you need to include the cases where the final position is at an edge (0 or 9). So, for example, instead of checking for less than 9, you should check for less than or equal 9.

:warning: Be careful about testing a challenge in an external REPL.
If you have misunderstood the challenge, it's also very likely that you will misinterpret the results.