Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Usual day / Help plz. My code is too short

# Defeat munchkins, collect coins. Everything as usual.
# Use AND to check existence and type in one statement.

while True:
    enemy = hero.findNearestEnemy()
    item= hero.findNearestItem()
    # With AND, the type is only checked if enemy exists.
    if enemy and enemy.type == "munchkin":
    if item and item.type=="coin":
        hero.moveXY(pos.x, pos.y)
# Collect item if it exists and its type is "coin".

1 Like

Try to remove the line 11

item.pos.x, item.pos.y

plus you would need a space

pos = item.pos

1 Like

It’s stylistic and doesn’t affect on the results.


sorry. I didn’t know. That was what it taught you.

1 Like

How did you complete it? I’ve tried to do what the others have said and it didnt work.
What did you do?

1 Like