Fair Battle Help


#1

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


#2

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


#3
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.


#4

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?


#5

Ah! Fixed the Problem! Thanks!


#6

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