# A fine mint Python

**URL:** <https://discourse.codecombat.com/t/a-fine-mint-python/8042>\
**Category:** Level Help\
**Created:** [June 15, 2016, 10:26pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042 "2016-06-15T22:26:24Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patricio\_Gerenni](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@Patricio\_Gerenni](https://discourse.codecombat.com/u/Patricio_Gerenni)\
**Post date:** [June 15, 2016, 10:26pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/1 "2016-06-15T22:26:24Z")

</div>

Hi, I talk Spanish but all the people here talk in English, so I’ll talk you my problem in English. I have a trouble with this level, my code is:  
def pickUpCoin():  
coin = hero.findNearestItem()  
if coin:  
hero.moveXY(coin.pos.x, coin.pos.y)

# Write the attackEnemy function below.

# Find the nearest enemy and attack them if they exist!

def findandattackenemy():  
hero.findNearestEnemy()  
if enemy:  
hero.attackEnemy  
while True:  
attackEnemy = self.findNearestEnemy() # ∆ Uncomment this line after you write an attackEnemy function.  
pickUpCoin()

I don’t know what’s the problem if any have the solution give me this please

---

<div class="post-metadata">

**Author:** ![Bryukh](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bryukh/32/19597_2.png) [@Bryukh](https://discourse.codecombat.com/u/Bryukh)\
**Post date:** [June 16, 2016, 4:44pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/2 "2016-06-16T16:44:37Z")

</div>

Could you format your code more accurately (use triple ` to wrap code) ? It will be easy to read your code and find a problem.

---

<div class="post-metadata">

**Author:** ![CryogenicMiner](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cryogenicminer/32/3985_2.png) [@CryogenicMiner](https://discourse.codecombat.com/u/CryogenicMiner)\
**Post date:** [June 16, 2016, 9:02pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/3 "2016-06-16T21:02:23Z")

</div>

Like Bryukh said, please format your question. Because we can not tell the indents of our code, and considering Python uses the indents it is important.

---

<div class="post-metadata">

**Author:** ![ant](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ant/32/3362_2.png) [@ant](https://discourse.codecombat.com/u/ant)\
**Post date:** [June 17, 2016, 7:06am UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/4 "2016-06-17T07:06:26Z")

</div>

You need to write the `attackEnemy()` function. This will be very similar to the `pickUpCoin()` function given in the default code:

```python
def attackEnemy():
    # find the nearest enemy
    # if there is an enemy:
        # attack it!

```

When done, just uncomment the `attackEnemy()` line:

```python
while True:
    attackEnemy()
    pickUpCoin()

```

---

<div class="post-metadata">

**Author:** ![Patricio\_Gerenni](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@Patricio\_Gerenni](https://discourse.codecombat.com/u/Patricio_Gerenni)\
**Post date:** [June 17, 2016, 1:03pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/5 "2016-06-17T13:03:12Z")

</div>

Sorry I newer in Python, so do you say me that I need to correct the code because you don’t understand the problem? With what?

---

<div class="post-metadata">

**Author:** ![Patricio\_Gerenni](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@Patricio\_Gerenni](https://discourse.codecombat.com/u/Patricio_Gerenni)\
**Post date:** [June 17, 2016, 1:12pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/6 "2016-06-17T13:12:03Z")

</div>

‘def findandattackenemy()’:  
hero.findNearestEnemy()  
‘if enemy’:  
hero.attackEnemy

This is my function. The game say that i needed to find the nearest enemy and then if the enemy exist attack him but this function don’t respond.  
The problem is that my hero begins to collect the money and then the enemy stands in front of my hero collecting the coins first. Do you have any function for me that it respond?

---

<div class="post-metadata">

**Author:** ![Bryukh](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bryukh/32/19597_2.png) [@Bryukh](https://discourse.codecombat.com/u/Bryukh)\
**Post date:** [June 17, 2016, 1:15pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/7 "2016-06-17T13:15:37Z")

</div>

I asked you to post your code as code, because now I don’t see indents and It’s hard to read you code.

---

<div class="post-metadata">

**Author:** ![Joshua\_Leon](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Joshua\_Leon](https://discourse.codecombat.com/u/Joshua_Leon)\
**Post date:** [September 12, 2016, 4:47pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/8 "2016-09-12T16:47:23Z")

</div>

Peons are trying to steal your coins!

```python
# Write a function to squash them before they can take your coins.

def pickUpCoin():
    coin = hero.findNearestItem()
    if coin:
        hero.moveXY(coin.pos.x, coin.pos.y)

# Write the attackEnemy function below.
# Find the nearest enemy and attack them if they exist!
enemy = hero.findNearestEnemy()
def attackEnemy():
    if enemy:
        hero.attack(enemy)

while True:
    attackEnemy() # ∆ Uncomment this line after you write an attackEnemy function.
    pickUpCoin()

thats my code idk what the problem is with the code it doesn't work the peons always get my coins

```

---

<div class="post-metadata">

**Author:** ![Joshua\_Leon](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Joshua\_Leon](https://discourse.codecombat.com/u/Joshua_Leon)\
**Post date:** [September 12, 2016, 4:47pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/9 "2016-09-12T16:47:55Z")

</div>

and no i don’t know how to format my code

---

<div class="post-metadata">

**Author:** ![Harry\_the\_Wanderer](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/harry_the_wanderer/32/5369_2.png) [@Harry\_the\_Wanderer](https://discourse.codecombat.com/u/Harry_the_Wanderer)\
**Post date:** [September 12, 2016, 4:49pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/10 "2016-09-12T16:49:14Z")

</div>

@Joshua_Leon if you highlight the code and use the `formatted text` option it should display the code as code.

![](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex016/uploads/codecombat/original/2X/7/78bce07c83c039fadd0e7e8fcc160e6d94012e12.png)

---

<div class="post-metadata">

**Author:** ![Joshua\_Leon](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Joshua\_Leon](https://discourse.codecombat.com/u/Joshua_Leon)\
**Post date:** [September 12, 2016, 4:50pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/11 "2016-09-12T16:50:17Z")

</div>

ok i tried that and reposted it did it work?

---

<div class="post-metadata">

**Author:** ![Harry\_the\_Wanderer](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/harry_the_wanderer/32/5369_2.png) [@Harry\_the\_Wanderer](https://discourse.codecombat.com/u/Harry_the_Wanderer)\
**Post date:** [September 12, 2016, 4:50pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/12 "2016-09-12T16:50:52Z")

</div>

yes it did, great! I am looking at the code.

---

<div class="post-metadata">

**Author:** ![Joshua\_Leon](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Joshua\_Leon](https://discourse.codecombat.com/u/Joshua_Leon)\
**Post date:** [September 12, 2016, 4:55pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/13 "2016-09-12T16:55:21Z")

</div>

oh, i moved the findNearestEnemy below def attackEnemy(): it fixed the problem

---

<div class="post-metadata">

**Author:** ![Serg](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/serg/32/3260_2.png) [@Serg](https://discourse.codecombat.com/u/Serg)\
**Post date:** [September 12, 2016, 4:55pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/14 "2016-09-12T16:55:55Z")

</div>

You only find a single enemy at the very start of your code execution.

Read it out loud:

1. You define pickUpCoin.
2. You find the nearest enemy.
3. You define attackEnemy.
4. You start a while-true loop.
5. You call attack enemy
6. You check if enemy exists.
7. You attack enemy.
8. You call pick up coin.
9. You find nearest coin.
10. You check if coin exists.
11. You move to the coin.
12. Repeat (while-true loop)

Look at step #2.

---

<div class="post-metadata">

**Author:** ![christian\_myers](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@christian\_myers](https://discourse.codecombat.com/u/christian_myers)\
**Post date:** [October 27, 2016, 4:43pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/15 "2016-10-27T16:43:41Z")

</div>

```python
# Peons are trying to steal your coins!
# Write a function to squash them before they can take your coins.
def pickUpCoin():
    coin = hero.findNearestItem()
    if coin:
        hero.moveXY(coin.pos.x, coin.pos.y)
# Write the attackEnemy function below.
# Find the nearest enemy and attack them if they exist!
def attackEnemy():
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
while True:
    attackEnemy() # ∆ Uncomment this line after you write an attackEnemy function.
pickUpCoin()

```

is this right?  
It won’t collect the coins?

---

<div class="post-metadata">

**Author:** ![Serg](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/serg/32/3260_2.png) [@Serg](https://discourse.codecombat.com/u/Serg)\
**Post date:** [October 27, 2016, 4:44pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/16 "2016-10-27T16:44:26Z")

</div>

Please format your code with 3x ( ` ) before and after your code block, so I can see your indentation.

---

<div class="post-metadata">

**Author:** ![christian\_myers](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@christian\_myers](https://discourse.codecombat.com/u/christian_myers)\
**Post date:** [October 27, 2016, 4:46pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/17 "2016-10-27T16:46:58Z")

</div>

I dont know how to do that sorry I am new?

---

<div class="post-metadata">

**Author:** ![Serg](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/serg/32/3260_2.png) [@Serg](https://discourse.codecombat.com/u/Serg)\
**Post date:** [October 27, 2016, 4:48pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/18 "2016-10-27T16:48:51Z")

</div>

> [@FAQ - Check Before Posting](https://discourse.codecombat.com/t/faq-check-before-posting/1027#code-help):
>
> Check This Awesome FAQ Before Posting … you know it’s sweet stuff! Might save your life some day. [I need help with my code!](#code-help) Check each level’s help guide for common tips If a level is too hard, try a different hero or different items Common error messages and how to debug them Post your code with radiant, harmonious formatting Personal coding help from the CodeCombat staff [The game is not working!](#not-working) It crashes It doesn’t load It’s slow The graphics aren’t showing up [Can you please fix …](#bugs)

Be sure to read the part about “radiant, harmonious formatting”

---

<div class="post-metadata">

**Author:** ![christian\_myers](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@christian\_myers](https://discourse.codecombat.com/u/christian_myers)\
**Post date:** [October 27, 2016, 4:51pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/19 "2016-10-27T16:51:31Z")

</div>

wow great service you cant help me !!! wow!

---

<div class="post-metadata">

**Author:** ![Serg](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/serg/32/3260_2.png) [@Serg](https://discourse.codecombat.com/u/Serg)\
**Post date:** [October 27, 2016, 4:55pm UTC](https://discourse.codecombat.com/t/a-fine-mint-python/8042/20 "2016-10-27T16:55:06Z")

</div>

I did it for you this time, but keep in mind in the future that improperly formatted Python code is hard to debug.

After formatting your code, I noticed that pickUpCoins isn’t indented. So it is never ran. Is this what you intended to do?

[Next page](https://discourse.codecombat.com/t/a-fine-mint-python/8042.md?page=2)
