# \[SOLVED\] Hero Dies in Usual Day (Python)

**URL:** https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373
**Category:** Level Help
**Created:** [May 7, 2017, 10:31pm UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373 "2017-05-07T22:31:48Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![jasonlava](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@jasonlava](https://discourse.codecombat.com/u/jasonlava)
#### Post date: [May 7, 2017, 10:31pm UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373/1 "2017-05-07T22:31:48Z")

</div>

New here. I’m trying to play Usual Day and for some reason, towards the end of the level, a mushroom appears and an enemy appears right in line with the mushroom. The hero goes towards the enemy, getting the mushroom on the way and dies.

# Defeat munchkins, collect coins. Everything as usual.

# Use AND to check existence and type in one statement.

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

 ![](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/4/4620c5ea5d65fb3f2a26b816645e819d7ed7f6f8.JPG)

I can have the hero move to another spot to avoid the mushroom but that’s eight lines of code and won’t complete the level.

---

<div class="post-metadata">

### Author: ![\_TD\_RodYT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/_td_rodyt/32/6285_2.png) [@\_TD\_RodYT](https://discourse.codecombat.com/u/_TD_RodYT)
#### Post date: [May 7, 2017, 10:44pm UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373/2 "2017-05-07T22:44:15Z")

</div>

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

```

No that is only 7 lines, so you should be able to complete the level. Also, make sure you format the code by wrapping it with three ticks. The result is `easier to read`.

---

<div class="post-metadata">

### Author: ![jasonlava](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@jasonlava](https://discourse.codecombat.com/u/jasonlava)
#### Post date: [May 7, 2017, 10:49pm UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373/3 "2017-05-07T22:49:55Z")

</div>

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

```

That’s better. It wants you to do it with under eight lines of code and that’s the seven lines. I’ll try with a different hero and see what happens.

---

<div class="post-metadata">

### Author: ![\_TD\_RodYT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/_td_rodyt/32/6285_2.png) [@\_TD\_RodYT](https://discourse.codecombat.com/u/_TD_RodYT)
#### Post date: [May 7, 2017, 10:51pm UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373/4 "2017-05-07T22:51:06Z")

</div>

Sure, try it with another hero. I tried that exact same code and it worked for me. I counted, only 7 lines, so it should fall into the under 8 category.

---

<div class="post-metadata">

### Author: ![jasonlava](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@jasonlava](https://discourse.codecombat.com/u/jasonlava)
#### Post date: [May 7, 2017, 10:57pm UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373/5 "2017-05-07T22:57:26Z")

</div>

Well. it works now. I logged off, logged back in and played it. I guess it’s just the way the objects were being spawned on that first round. It just so happened a poisonous mushroom was in the way of getting to an enemy. Thanks!

---

<div class="post-metadata">

### Author: ![Fi\_Stach](https://avatars.discourse-cdn.com/v4/letter/f/958977/32.png) [@Fi\_Stach](https://discourse.codecombat.com/u/Fi_Stach)
#### Post date: [October 21, 2017, 6:59am UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373/6 "2017-10-21T06:59:54Z")

</div>

I think the mushroom is there on purpose. And there is a trick to avoid it!

In the last line, don’t go exactly to the item, you can pick it up even if you go to

hero.moveXY (item.pos.x-1, item.pos.y-1);

This way the distance to mushroom is long enough to avoid it 🙂

---

<div class="post-metadata">

### Author: ![Hellenar](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hellenar/32/9100_2.png) [@Hellenar](https://discourse.codecombat.com/u/Hellenar)
#### Post date: [October 21, 2017, 11:09pm UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373/7 "2017-10-21T23:09:06Z")

</div>

Or submit for a different seed. Also, please do not revive dead threads 🙂

---

<div class="post-metadata">

### Author: ![Karthikeya\_Turimalla](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/karthikeya_turimalla/32/12151_2.png) [@Karthikeya\_Turimalla](https://discourse.codecombat.com/u/Karthikeya_Turimalla)
#### Post date: [May 8, 2020, 6:53pm UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373/8 "2020-05-08T18:53:11Z")

</div>

but the hero goes to defeat a munchkin getting poisoned on the way

---

<div class="post-metadata">

### Author: ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)
#### Post date: [May 9, 2020, 9:20am UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373/9 "2020-05-09T09:20:21Z")

</div>

Hi, do you need help with this level? If so please post your code formatted, with three ``` at the start and end of your code on a new lines.  
Danny

---

<div class="post-metadata">

### Author: ![floridamanog](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/floridamanog/32/21574_2.png) [@floridamanog](https://discourse.codecombat.com/u/floridamanog)
#### Post date: [December 16, 2020, 10:20am UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373/10 "2020-12-16T10:20:26Z")

</div>

help me im sort of stuck

---

<div class="post-metadata">

### Author: ![floridamanog](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/floridamanog/32/21574_2.png) [@floridamanog](https://discourse.codecombat.com/u/floridamanog)
#### Post date: [December 16, 2020, 10:21am UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373/11 "2020-12-16T10:21:37Z")

</div>

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

```

my code isnt working as i would like it is just finding the enemy and not attacking it, nor moving at all

---

<div class="post-metadata">

### Author: ![PeterPalov](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/peterpalov/32/45280_2.png) [@PeterPalov](https://discourse.codecombat.com/u/PeterPalov)
#### Post date: [December 16, 2020, 11:08am UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373/12 "2020-12-16T11:08:16Z")

</div>

Hello! I think your code isn’t working, because it isn’t in While True.  
Everything (item, if’s moveXY) should be in the While True loop. Not only enemy.

---

<div class="post-metadata">

### Author: ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)
#### Post date: [December 16, 2020, 12:50pm UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373/13 "2020-12-16T12:50:15Z")

</div>

> [@floridamanog](#):
>
> ```python
> # With AND, the type is only checked if enemy exists.
> if enemy and enemy.type == "munchkin":
> hero.attack(enemy);
> pass
> # Find the nearest item.
> item = hero.findNearestItem()
> # Collect item if it exists and its type is "coin".
> if item and item.type == "coin":
> hero.moveXY (item.pos.x, item.pos.y);
> pass
> 
> ```

Like @PeterPalov said, you need to put all of this into the while true loop.

---

<div class="post-metadata">

### Author: ![floridamanog](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/floridamanog/32/21574_2.png) [@floridamanog](https://discourse.codecombat.com/u/floridamanog)
#### Post date: [March 22, 2021, 2:19pm UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373/14 "2021-03-22T14:19:17Z")

</div>

help me i still cant do it, im not sure what to do

---

<div class="post-metadata">

### Author: ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)
#### Post date: [March 22, 2021, 5:26pm UTC](https://discourse.codecombat.com/t/solved-hero-dies-in-usual-day-python/11373/15 "2021-03-22T17:26:04Z")

</div>

Please could you post your new code.
