Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Joao Cid
Joao Cid
7,706 Points

What's wrong with the code? The examples tested work fine.

Hi... No sure what can be wrong with my code for this challenge... In fact, it works with the 3 examples presented above in the comments, as also with some others I tried on my own, but I am still getting the message "Bummer: Try again!". Thanks in advance for any hint or advice.

movement.py
# 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
    dir_x, dir_y = direction
    new_x_try = x + dir_x
    new_y_try = y + dir_y
    if new_x_try < 0 or new_x_try > 9 or new_y_try < 0 or new_y_try > 9:
        hp -= 5
    else:
        x, y = new_x_try, new_y_try
    return x, y, hp

2 Answers

Joao Cid
Joao Cid
7,706 Points

Hi, Brendan... many thanks for your prompt reply... Something should be wrong, still... as I still can't finish it and move forward. I have tried to delete everything and re-paste it, but still no success... As said before, the code runs fine in the Workspaces and the tests I have tried run successfully, bu I would like to finish this cleanly. Again, many thanks for your time. P.S.: I even have tried to logout and lo in again... just i case, by the way... ;)

Chul Kim
Chul Kim
2,341 Points

sometimes it helps to re-type the solution instead of just pasting.

Joao Cid
Joao Cid
7,706 Points

Hi, Chul Kim, many thanks for your reply and suggestion... In fact, someone (and/or somehow) should have reset it in the meanwhile and after re-typing exactly the same, it finally worked... :) Again, many thanks.