# Usual day help shorting the code to lower than 8 lines

**URL:** https://discourse.codecombat.com/t/usual-day-help-shorting-the-code-to-lower-than-8-lines/19465
**Category:** Level Help
**Created:** [October 27, 2019, 8:13pm UTC](https://discourse.codecombat.com/t/usual-day-help-shorting-the-code-to-lower-than-8-lines/19465 "2019-10-27T20:13:04Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Zijun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/zijun/32/10900_2.png) [@Zijun](https://discourse.codecombat.com/u/Zijun)
#### Post date: [October 27, 2019, 8:13pm UTC](https://discourse.codecombat.com/t/usual-day-help-shorting-the-code-to-lower-than-8-lines/19465/1 "2019-10-27T20:13:04Z")

</div>

could you help me on the level usual day in the backwoods forest? this was the code could you shorten it?

```python
while True:
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type == "munchkin":
        hero.attack(enemy)
    item = hero.findNearestItem()
    if item and item.type == "coin":
        pos = item.pos
        x=pos.x
        y=pos.y
        hero.moveXY(x, y)

```

---

<div class="post-metadata">

### Author: ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)
#### Post date: [October 28, 2019, 9:36am UTC](https://discourse.codecombat.com/t/usual-day-help-shorting-the-code-to-lower-than-8-lines/19465/2 "2019-10-28T09:36:24Z")

</div>

> [@Zijun](#):
>
> item = hero.findNearestItem()

Hi!  
You don’t need to define item.pos, pos.x and pos.y . These three lines are unnecessary )  
Good luck!

---

<div class="post-metadata">

### Author: ![Zijun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/zijun/32/10900_2.png) [@Zijun](https://discourse.codecombat.com/u/Zijun)
#### Post date: [October 28, 2019, 5:54pm UTC](https://discourse.codecombat.com/t/usual-day-help-shorting-the-code-to-lower-than-8-lines/19465/3 "2019-10-28T17:54:03Z")

</div>

but if I try It will not work

---

<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: [October 28, 2019, 6:07pm UTC](https://discourse.codecombat.com/t/usual-day-help-shorting-the-code-to-lower-than-8-lines/19465/4 "2019-10-28T18:07:34Z")

</div>

You can use the item.pos.x and item.pos.y directly in the moveXY function.

---

<div class="post-metadata">

### Author: ![Zijun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/zijun/32/10900_2.png) [@Zijun](https://discourse.codecombat.com/u/Zijun)
#### Post date: [October 28, 2019, 6:12pm UTC](https://discourse.codecombat.com/t/usual-day-help-shorting-the-code-to-lower-than-8-lines/19465/5 "2019-10-28T18:12:32Z")

</div>

but I have 9 statements instead of 8

```python
while True:
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type == "munchkin":
        hero.attack(enemy)
    item = hero.findNearestItem()
    if item and item.type == "coin":
        x=item.pos
        y=item.pos
        hero.moveXY(item.pos.x, item.pos.y)

```

---

<div class="post-metadata">

### Author: ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)
#### Post date: [October 28, 2019, 8:34pm UTC](https://discourse.codecombat.com/t/usual-day-help-shorting-the-code-to-lower-than-8-lines/19465/6 "2019-10-28T20:34:17Z")

</div>

```python
while True:
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type == "munchkin":
        hero.attack(enemy)
    item = hero.findNearestItem()
    if item and item.type == "coin":
        x=item.pos
        y=item.pos
        hero.moveXY(item.pos.x, item.pos.y)

```

This code is correct, just put out lines defining “x” and “y”.

 ![usual%20day](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/d/d3e499bfa77496c5974200cf3f85e64bea160270.jpeg)

P.S. It’s possible to make this lvl with 6 lines ) (at least with Pyton, idk about other languages)

---

<div class="post-metadata">

### Author: ![Zijun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/zijun/32/10900_2.png) [@Zijun](https://discourse.codecombat.com/u/Zijun)
#### Post date: [October 28, 2019, 10:17pm UTC](https://discourse.codecombat.com/t/usual-day-help-shorting-the-code-to-lower-than-8-lines/19465/7 "2019-10-28T22:17:00Z")

</div>

thank you very much, It worked!
