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 trial

Python Python Collections (2016, retired 2019) Dungeon Game Hit points

Henrique Costardi
Henrique Costardi
4,883 Points

Not sure why its not passing

Hello guys.

Im confused.

when i run in my ide the code has the correct behavior.

Anyone can see why its not passing the test?

thanks in advance

# 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
        x += a
        y += b
    return x, y, hp

2 Answers

Steven Parker
Steven Parker
229,952 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:

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: