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 trialDaniel Sutton
3,414 PointsHit Points Challenge: help with coordinating the coordinates and direction
I was hoping to get some critique on my attempt attached to this post: I think I have the main components necessary, but I am not sure what is out of order, or nested improperly.
# 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
if direction == "LEFT":
x -= 1
if direction == "RIGHT":
x += 1
if direction == "UP":
y -= 1
if direction == "DOWN":
y += 1
def get_moves(player):
moves = ["LEFT", "RIGHT", "UP", "DOWN"]
if x == 0:
moves.remove("LEFT")
if x == 9:
moves.remove("RIGHT")
if y == 0:
moves.remove("UP")
if y == 9:
moves.remove("DOWN")
return moves
if direction not in moves:
hp -= 5
return x, y, hp
1 Answer
Steven Parker
231,275 PointsThe instructions tell you that the function will take a "three-part tuple player
and a direction
tuple that's two parts".
Also, if you look at the comments in the boilerplate code, you'll see examples of how the function will be called.
It looks like your function is expecting "direction" to be a string with a descriptive word instead of the tuple containing the offset values. You'll need a significantly different approach to handle the arguments that will be provided.