Hello, I’ve been stuck on this level for a while, and I was trying to find out what to do. It keeps saying that enemy.health
is not a variable after it accepted it as on before.
Someone tell me what’s going on and how I can fix it.
Here’s the code:
# 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
enemy= strongest
strongestHealth = enemy.health
# Increment enemyIndex
enemyIndex +=1
return strongest
enemies = hero.findEnemies()
leader = findStrongestEnemy(enemies)
if leader:
hero.say(leader)