[SOLVED] Brittle morale help:

def findStrongestEnemy(enemies):
    strongest = None
    strongestHealth = 0
    enemyIndex = 0
    while enemyIndex < len(enemies):
        enemy = enemies[enemyIndex]
        if enemy.health > strongestHealth:
            strongestHealth = enemy.Health
        enemyIndex += 1
    return strongest
    enemies = hero.findEnemies()
    leader = findStrongestEnemy(enemies)
    if leader:
        hero.say(leader)

it says strongest is not defined

Why do you call a function in that function?

Andrei

it was at the beginning with strongest = none

So there is no strongest enemy?

def findStrongestEnemy(enemies):
    strongest = enemy
    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
            strongestHealth = enemy.Health
        # Increment enemyIndex
        enemyIndex += 1

return strongest

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

even when I put enemy it said strongest was not defined

It is because your function not return anything.

Andrei

so what should I put for the strongest = ?

And where do you say who the enemy is here?

Andrei

1 Like

ok I am confused about what your trying to say here

1 Like

There the enemy is None, so strongest is None too.

Andrei

1 Like

so I should put the strongest but how do I put the strongest if I don’t know who is the strongest

1 Like

This is what this loop should find out.

Andrei

but how do I get the strongest enemy from that loop

Look closer at this comment:

Andrei

so you mean the strongest = enemy sets the strongest to equal as if it were a regular enemy but the strongest enemy

So do you understand now how to solve the level?

Andrei

Again, why do you not return anything from the function? And you did not correct this:

Andrei

so I figured out three options to put enemy leader and strongest but none of them are working so what do I do about?