Fair Battle Help

My code isn’t working and I can’t see the reason. Here’s my code.

def sumHealth(enemies):
    enemyHealth = 0
    index = 0
    while index < len(enemies):
        enemyHealth = enemyHealth + enemies[index].health
        index += 1
        def sumHealth(friends):
            friendHealth = 0
            index = 0
            while index < len(friends):
                friendHealth = friendHealth + friends[index].health
                index += 1
                if friendHealth > enemyhealth:
                    hero.say("Attack")

Please Help

Why do you define the function inside the function with the same name? O_o

def sumHealth(enemies):
    enemyHealth = 0
    index = 0
    while index < len(enemies):
        enemyTotalHealth = enemyHealth + enemies[index].health
        index += 1
        def sumHealth(friends):
            friendHealth = 0
            index = 0
            while index < len(friends):
                friendTotalHealth = friendHealth + friends[index].health
                index += 1
                if friendTotalHealth > enemyTotalHealth:
                    hero.say("Attack")

Is this easier to find the problem. Still doesn’t work.

I’m not sure what you are trying to do with this code. Let me explain your code:
In the function sumHealth you iterate enemies and summarise their health in enemyTotalHealth, then for each of the enemies you define again and again the function sumHealth (why???). That function checks if accumulating healths of friends are greater than enemyTotalHealth. But I don’t see where you call any of that functions.

I recommend you return to the Forest and revise levels about functions. Also is it the whole code?

Ah! Fixed the Problem! Thanks!

Use flag to start and you can wait for a few seconds and biuld a flag.try more!