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 trialIgor Ozherelyev
2,052 PointsIt works well in terminal but workspace says it's wrong
It works well in terminal but workspace says it's wrong
# 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
x1, y1 = direction
if x + x1 < 0 or x + x1 > 9 or y + y1 < 0 or y + y1 > 9:
hp -= 5
return x, y, hp
2 Answers
Eric M
11,546 PointsHi Igor,
As well as updating the HP, and not moving the player, when a player would hit a wall, you also need to update the player's position (the returned x, y
values) when the player has a valid move (that does not hit a wall).
Good luck!
Eric
Steven Parker
231,275 PointsHow did you test it? I tried passing the arguments shown in the examples and none of them produce the output the example shows to expect.
In fact, in all of the tests, the outputs are exactly the same as the inputs. That might serve as a hint.
Also, just in general you should always bear in mind that the workspaces don't know anything about the challenge objectives. If you misinterpret the objectives, you can write code that will seem to perform correctly in the workspace, but will still not pass the challenge. The same can happen if your testing is less stringent than the challenges. You can count on the challenge to always use more stringent tests internally than those shown in the examples.