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 trialNicolas Buzeta
Courses Plus Student 93 PointsAs far as i can tell this code is working, what is wrong with it
I know i'm not checking if the direction tuple is only moves in one direction and at a magnitude of 1 but the error i receive is that the player isn't taking damage. However, running it on my own IDE shows that is does work.
# 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
dx, dy = direction
nx = x + dx
ny = y + dy
if nx == -1 or nx == 10 or ny == -1 or nx == 10:
nx = x
ny = y
hp -= 5
return nx, ny, hp
1 Answer
Stuart Wright
41,120 PointsThere is one small error in your code:
if nx == -1 or nx == 10 or ny == -1 or nx == 10:
^
should be:
if nx == -1 or nx == 10 or ny == -1 or ny == 10:
^