# 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):
enemy = hero.findNearestEnemy()
# 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
enemy = strongest
enemy.health = strongestHealth
# Increment enemyIndex
enemyIndex += 1
return strongest
enemies = hero.findEnemies()
leader = findStrongestEnemy(enemies)
if leader:
hero.say(leader)
You are already passing the array ‘enemies’ to the definition, so you can delete the second line in:
while enemyIndex < len(enemies):
enemy = hero.findNearestEnemy()
In this next block, you have the variables reversed:
# Set `strongest` to enemy
# Set strongestHealth to enemy.health
enemy = strongest
enemy.health = strongestHealth
For example, “Set ‘strongest’ to enemy” means to make ‘strongest’ equal to ‘eemy’, not the other way around…
2 Likes
Thanks! It worked
1 Like
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.