# Clash of the Clones Python

**URL:** <https://discourse.codecombat.com/t/clash-of-the-clones-python/22576>\
**Category:** Level Help\
**Created:** [June 26, 2020, 6:50pm UTC](https://discourse.codecombat.com/t/clash-of-the-clones-python/22576 "2020-06-26T18:50:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![KierynM](https://avatars.discourse-cdn.com/v4/letter/k/3e96dc/32.png) [@KierynM](https://discourse.codecombat.com/u/KierynM)\
**Post date:** [June 26, 2020, 6:50pm UTC](https://discourse.codecombat.com/t/clash-of-the-clones-python/22576/1 "2020-06-26T18:50:45Z")

</div>

I am having trouble with my code on this level. I am trying to find the weakest enemy and then attack that enemy but nothing is happening. PLS HELP!

```python
# This function should go through the enemy array and find the weakest enemy
def findWeakestEnemy():
    enemies = hero.findEnemies()
    weakest = None
    leastHealth = 99999
    enemyIndex = 0
    # Picking out individual enemy from the array and testing his health agains leastHealth
    if enemyIndex < len(enemies):
        enemy = enemies[enemyIndex]
        if enemy.health < leastHealth:
            weakest = enemy
            leastHealth = enemy.health
            enemyIndex += 1
            return

while True:
    enemy = findWeakestEnemy()
    if enemy:
        hero.attack(enemy)

```

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [June 26, 2020, 7:12pm UTC](https://discourse.codecombat.com/t/clash-of-the-clones-python/22576/2 "2020-06-26T19:12:08Z")

</div>

Howdy and welcome to the forum! Please repost your code, properly formatted. You can learn how here: [[Essentials] How To Post/Format Your Code Correctly](https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521)

---

<div class="post-metadata">

**Author:** ![KierynM](https://avatars.discourse-cdn.com/v4/letter/k/3e96dc/32.png) [@KierynM](https://discourse.codecombat.com/u/KierynM)\
**Post date:** [June 26, 2020, 7:50pm UTC](https://discourse.codecombat.com/t/clash-of-the-clones-python/22576/3 "2020-06-26T19:50:52Z")

</div>

Hi dedreous,

Thanks for the tip. I’m sure you have to say that hundreds of times a day!

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [June 26, 2020, 7:54pm UTC](https://discourse.codecombat.com/t/clash-of-the-clones-python/22576/4 "2020-06-26T19:54:59Z")

</div>

Heh…unfortunately 'tis true. 🙂

The first issue I see is with:

```python
    if enemyIndex < len(enemies):

```

Rather than using an ‘if’ statement, you should use a conditional loop instead. As written now, ‘enemyIndex’ will eventually become \>= len(enemies), since you are incrementing it, so eventually, this entire ‘if’ block with be ignored.

---

<div class="post-metadata">

**Author:** ![TinyGoliath06](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@TinyGoliath06](https://discourse.codecombat.com/u/TinyGoliath06)\
**Post date:** [August 19, 2020, 6:24pm UTC](https://discourse.codecombat.com/t/clash-of-the-clones-python/22576/5 "2020-08-19T18:24:22Z")

</div>

Can you please help me with Clash of Clones? Here is my code:

```python
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        if hero.isReady("bash"):
            hero.bash(enemy)
        else:
            hero.attack(enemy)
            if hero.health <= 75:
                hero.moveXY(41, 67)
                break

```

---

<div class="post-metadata">

**Author:** ![098765432123](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/098765432123/32/25850_2.png) [@098765432123](https://discourse.codecombat.com/u/098765432123)\
**Post date:** [August 20, 2020, 5:04pm UTC](https://discourse.codecombat.com/t/clash-of-the-clones-python/22576/6 "2020-08-20T17:04:42Z")

</div>

is there an error or what? @TinyGoliath06

---

<div class="post-metadata">

**Author:** ![098765432123](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/098765432123/32/25850_2.png) [@098765432123](https://discourse.codecombat.com/u/098765432123)\
**Post date:** [August 20, 2020, 5:05pm UTC](https://discourse.codecombat.com/t/clash-of-the-clones-python/22576/7 "2020-08-20T17:05:53Z")

</div>

i suggest using not so good equipment to
