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!
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
Henrique Costardi4,883 Points
Not sure why its not passing
when i run in my ide the code has the correct behavior.
Anyone can see why its not passing the test?
thanks in advance
# 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 a, b = direction if 10>(x + a)<0: hp -= 5 elif 10>(y + b)<0: hp -= 5 else: x += a y += b return x, y, hp
Steven Parker225,652 Points
10>(x + a)<0 is not a valid expression
The rules of operator associativity don't accomodate building a complex expression like that. But you can combine multiple expressions using "or" if you want.
Also, it looks like one of your comparisons is reversed. And the grid limit is 9, not 10.
if x + a > 9 or x + a < 0:
Iain SimmonsTreehouse Moderator 32,303 Points
If you look closely at your code and follow through with the shown test numbers, it's not really doing what is asked.
You want to first check for
(x + a) or
(y + b) to be greater than 9, not 10, because 9 is already the edge/wall.
Also, you can't use the range syntax (
x < y < z) because you're actually looking for values outside of the range.
Instead, use an
or in the conditionals, and repeat the
(x + a) part:
if (x + a) < 0 or (x + a) > 9: