# Please Help (Clash of Clones- Python)

**URL:** <https://discourse.codecombat.com/t/please-help-clash-of-clones-python/19241>\
**Category:** Level Help\
**Created:** [September 18, 2019, 4:47pm UTC](https://discourse.codecombat.com/t/please-help-clash-of-clones-python/19241 "2019-09-18T16:47:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Princess\_Fayette](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/princess_fayette/32/10730_2.png) [@Princess\_Fayette](https://discourse.codecombat.com/u/Princess_Fayette)\
**Post date:** [September 18, 2019, 4:47pm UTC](https://discourse.codecombat.com/t/please-help-clash-of-clones-python/19241/1 "2019-09-18T16:47:17Z")

</div>

I’ve tried several ways and no matter how i try to fix my code my hero just continues to electrocute the enemy instead of bashing them.  
Please help me, here is my current code:

```python
while True:
    enemy = hero.findNearestEnemy()
    hero.shield()
    
    if hero.canElectrocute(enemy):
            hero.electrocute(enemy)
    if enemy and enemy.type != "sand-yak":
        hero.shield()
        if hero.distanceTo(enemy) < 10:
            hero.bash(enemy)
        

```

---

<div class="post-metadata">

**Author:** ![xantar](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xantar/32/8881_2.png) [@xantar](https://discourse.codecombat.com/u/xantar)\
**Post date:** [September 18, 2019, 6:42pm UTC](https://discourse.codecombat.com/t/please-help-clash-of-clones-python/19241/2 "2019-09-18T18:42:55Z")

</div>

Hello,  
CanElectrocute only checks if enemy can be electrocuted (distance, type etc.), but you also need to check if you are ready to electrocute (use `hero.isReady()`). You also need to check if you can bash.

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [September 18, 2019, 6:52pm UTC](https://discourse.codecombat.com/t/please-help-clash-of-clones-python/19241/3 "2019-09-18T18:52:18Z")

</div>

Hi Princess\_Fayette. Welcome to Discourse. Your syntax is okay but the main issue I see is the structure of your code. Let’s take it line by line.

```python
while True:
    enemy = hero.findNearestEnemy() # yes, we need this first.
    hero.shield() # This is saying to shield for no apparent reason. Just shield.
                 # Probably not a good idea. Shielding is best when combined with a conditional for circumstances to shield.
    if hero.canElectrocute(enemy): # What if there's no enemy? Code will fail. Always check if there's
            hero.electrocute(enemy) # an enemy first, before telling your hero to interact with the enemy.
    if enemy and enemy.type != "sand-yak": # This should be placed immediately after defining enemy
        hero.shield() # and before any attack code.
        if hero.distanceTo(enemy) < 10: # This won't run at all. It would work better as an else statement
            hero.bash(enemy) # so that it runs during the electrocute cooldown.
        

```

Try switching things around, use elif and else conditionals, and it should work.  
Define enemy.  
Check for enemy.  
Electrocute enemy.  
Bash enemy.  
Shield.
