Help with brittle morale (python)

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)

please respond to my code soon

1 Like

Hi @Colton_Reilly and welcome to the forum! :partying_face:

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

Andrei

1 Like

Hi @Colton_Reilly and welcome to the forum! :tada: :partying_face: I can help with @AnSeDra

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)

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)

I’ll format it for you this time

#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)

all of this should be in the while loop you made