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 trialemil sanchez
3,089 Pointsneed some help.. i seem to be getting the right output... but still getting the bummer message...
i assume.. y axis does should have no other correct value than 0... since:
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)
all my output is showing to be correct... unless i have not understood the problem description correctly... 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
lr, ud = direction
m = x + lr
m2 = ud
def valid_moves(a, b):
if a in range(0, 9):
return "half"
if b == 0:
return "valid"
else:
return "invalid"
else:
return "invalid"
status_m = valid_moves(m, m2)
if status_m == "valid":
x = m
elif status_m == "half":
x = m
if m not in range(0, 9) or m2 != 0:
hp -= 5
else:
hp -= 5
return x, y, hp
result = move((9, 9, 5), (3, 0))
print(result)
2 Answers
Oskar Lundberg
9,534 PointsAs far as I know, you can't have a function inside a function. I will just share my solution to the challenge. I hope it will help you :D
def move(player, direction):
x, y, hp = player
dx, dy = direction
if x + dx > 9:
hp -= 5
x = 9
elif x + dx < 0:
hp -= 5
x = 0
else:
x += dx
if y + dy > 9:
hp -= 5
y = 9
elif y + dy < 0:
hp -= 5
y = 0
else:
y += dy
return x, y, hp
I know that it isn't the most DRY code since I'm doing the same thing for both x and y, but hopefully it will help you :D
emil sanchez
3,089 Pointsthanks oskar :)