# Help with brittle morale (python)

**URL:** <https://discourse.codecombat.com/t/help-with-brittle-morale-python/23901>\
**Category:** Level Help\
**Created:** [September 4, 2020, 8:04pm UTC](https://discourse.codecombat.com/t/help-with-brittle-morale-python/23901 "2020-09-04T20:04:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colton\_Reilly](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/colton_reilly/32/13243_2.png) [@Colton\_Reilly](https://discourse.codecombat.com/u/Colton_Reilly)\
**Post date:** [September 4, 2020, 8:04pm UTC](https://discourse.codecombat.com/t/help-with-brittle-morale-python/23901/1 "2020-09-04T20:04:33Z")

</div>

here’s my code. I’ve been stuck on this level can you help?

# You have one arrow. Make it count!

# This should return the enemy with the most health.

def findStrongestEnemy(enemies):  
strongest = None  
strongestHealth = 0  
enemyIndex = 0  
# While enemyIndex is less than the length of enemies:  
while enemyIndex \< len(enemies):  
# Set an enemy variable to enemies[enemyIndex]  
enemy = enemies[enemyIndex]  
# If enemy.health is greater than strongestHealth  
if enemy.health \> strongestHealth:  
# Set `strongest` to enemy  
# Set strongestHealth to enemy.health  
strongest = enemy  
strongesHealth = enemy.health  
# Increment enemyIndex  
enemyIndex += 1

```
return strongest

```

enemies = hero.findEnemies()  
leader = findStrongestEnemy(enemies)  
if leader:  
hero.say(leader)

---

<div class="post-metadata">

**Author:** ![Colton\_Reilly](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/colton_reilly/32/13243_2.png) [@Colton\_Reilly](https://discourse.codecombat.com/u/Colton_Reilly)\
**Post date:** [September 4, 2020, 8:05pm UTC](https://discourse.codecombat.com/t/help-with-brittle-morale-python/23901/2 "2020-09-04T20:05:49Z")

</div>

please respond to my code soon

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [September 4, 2020, 8:11pm UTC](https://discourse.codecombat.com/t/help-with-brittle-morale-python/23901/3 "2020-09-04T20:11:27Z")

</div>

Hi @Colton_Reilly and welcome to the forum! 🥳

Can you format your code as it is described below so we will be able to help you?

> [@\[Essentials\] How To Post/Format Your Code Correctly](https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521):
>
> Formatting your code before posting code is essential to our community, and if you don’t we might not be able to help frowning Everyone must know how to format ALL of your code properly. It’s really easy and only requires a very small amount of effort. To post your code from the game , use the \</\> button or it won’t format properly. When you click the \</\> button, the following will appear: Please paste ALL …

Andrei

---

<div class="post-metadata">

**Author:** ![Jake\_Doggy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jake_doggy/32/13887_2.png) [@Jake\_Doggy](https://discourse.codecombat.com/u/Jake_Doggy)\
**Post date:** [September 4, 2020, 8:27pm UTC](https://discourse.codecombat.com/t/help-with-brittle-morale-python/23901/4 "2020-09-04T20:27:08Z")

</div>

Hi @Colton_Reilly and welcome to the forum! 🎉 🥳 I can help with @AnSeDra

---

<div class="post-metadata">

**Author:** ![Colton\_Reilly](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/colton_reilly/32/13243_2.png) [@Colton\_Reilly](https://discourse.codecombat.com/u/Colton_Reilly)\
**Post date:** [September 4, 2020, 9:32pm UTC](https://discourse.codecombat.com/t/help-with-brittle-morale-python/23901/5 "2020-09-04T21:32:57Z")

</div>

here’s the formatted version please help

# You have one arrow. Make it count!

# This should return the enemy with the most health.

def findStrongestEnemy(enemies):  
strongest = None  
strongestHealth = 0  
enemyIndex = 0  
# While enemyIndex is less than the length of enemies:  
while enemyIndex \< len(enemies):  
# Set an enemy variable to enemies[enemyIndex]  
enemy = enemies[enemyIndex]  
# If enemy.health is greater than strongestHealth  
if enemy.health \> strongestHealth:  
# Set `strongest` to enemy  
# Set strongestHealth to enemy.health  
strongest = enemy  
strongesHealth = enemy.health  
# Increment enemyIndex  
enemyIndex += 1

```
return strongest

```

enemies = hero.findEnemies()  
leader = findStrongestEnemy(enemies)  
if leader:  
hero.say(leader)

```python

```

---

<div class="post-metadata">

**Author:** ![Colton\_Reilly](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/colton_reilly/32/13243_2.png) [@Colton\_Reilly](https://discourse.codecombat.com/u/Colton_Reilly)\
**Post date:** [September 4, 2020, 9:35pm UTC](https://discourse.codecombat.com/t/help-with-brittle-morale-python/23901/6 "2020-09-04T21:35:19Z")

</div>

sorry this should be it

# You have one arrow. Make it count!

# This should return the enemy with the most health.

def findStrongestEnemy(enemies):  
strongest = None  
strongestHealth = 0  
enemyIndex = 0  
# While enemyIndex is less than the length of enemies:  
while enemyIndex \< len(enemies):  
# Set an enemy variable to enemies[enemyIndex]  
enemy = enemies[enemyIndex]  
# If enemy.health is greater than strongestHealth  
if enemy.health \> strongestHealth:  
# Set `strongest` to enemy  
# Set strongestHealth to enemy.health  
strongest = enemy  
strongesHealth = enemy.health  
# Increment enemyIndex  
enemyIndex += 1

```
return strongest

```

enemies = hero.findEnemies()  
leader = findStrongestEnemy(enemies)  
if leader:  
hero.say(leader)

```python

```

---

<div class="post-metadata">

**Author:** ![Jake\_Doggy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jake_doggy/32/13887_2.png) [@Jake\_Doggy](https://discourse.codecombat.com/u/Jake_Doggy)\
**Post date:** [September 4, 2020, 10:12pm UTC](https://discourse.codecombat.com/t/help-with-brittle-morale-python/23901/7 "2020-09-04T22:12:49Z")

</div>

I’ll format it for you this time

```python
#You have one arrow. Make it count!
#This should return the enemy with the most health.
def findStrongestEnemy(enemies):
strongest = None
strongestHealth = 0
enemyIndex = 0
# While enemyIndex is less than the length of enemies:
while enemyIndex < len(enemies):
# Set an enemy variable to enemies[enemyIndex]
enemy = enemies[enemyIndex]
# If enemy.health is greater than strongestHealth
if enemy.health > strongestHealth:
# Set strongest to enemy
# Set strongestHealth to enemy.health
strongest = enemy
strongesHealth = enemy.health
# Increment enemyIndex
enemyIndex += 1

return strongest
enemies = hero.findEnemies()
leader = findStrongestEnemy(enemies)
if leader:
hero.say(leader)

```

---

<div class="post-metadata">

**Author:** ![Jake\_Doggy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jake_doggy/32/13887_2.png) [@Jake\_Doggy](https://discourse.codecombat.com/u/Jake_Doggy)\
**Post date:** [September 4, 2020, 10:14pm UTC](https://discourse.codecombat.com/t/help-with-brittle-morale-python/23901/8 "2020-09-04T22:14:49Z")

</div>

> [@Jake\_Doggy](#):
>
> ```python
> enemy = enemies[enemyIndex]
> # If enemy.health is greater than strongestHealth
> if enemy.health > strongestHealth:
> # Set strongest to enemy
> # Set strongestHealth to enemy.health
> strongest = enemy
> strongesHealth = enemy.health
> # Increment enemyIndex
> enemyIndex += 1
> 
> ```

all of this should be in the while loop you made

> [@Jake\_Doggy](#):
>
> `while enemyIndex < len(enemies):`
