Python Fair Battle Level Help

# Attack when your soldiers' total health is greater
# than the ogres' total health

# This function return the sum of all the units' health.
def sumHealth(units):
    totalHealth = 0
    # Complete this function:
    
    return totalHealth

while True:
    friends = hero.findFriends()
    enemies = hero.findEnemies()
    # Get the total health of your soldiers and the ogres.
    if sumHealth(friends) <= sumHealth(enemies):
        hero.say("Wait")
    # Say "Attack" when your side has more total health.
    else:
        hero.say("ATTACK!!!")

Help me my code is not working

Hi Everncast and welcome to the forum! You didn’t complete the sumHealth function.

What is the sumHealth function? I don’t think I know that.

This is the function you should complete.

Thank you for helping me with that

Do you need any more help?

# Attack when your soldiers' total health is greater
# than the ogres' total health

# This function return the sum of all the units' health.
def sumHealth(units):
    totalHealth = 0
    # Complete this function:
    sum(totalHealth)
    return totalHealth

while True:
    friends = hero.findFriends()
    enemies = hero.findEnemies()
    # Get the total health of your soldiers and the ogres.
    if sumHealth(friends) <= sumHealth(enemies):
        hero.say("Wait")
    # Say "Attack" when your side has more total health.
    else:
        hero.say("ATTACK!!!")

I keep losing the battle and I don’t know why.

Your totalHealth should be the sum of the healths of the units in the units array.

so would it be

totalHealth = sum(friends)

No. You should put:

    for unit in units:
            totalHealth += unit.health

instead of this:

Thank you so much @AnSeDra for helping me with this it worked now :crocodile:

No problem :wink: :slight_smile:

so i tried it with the

   for unit in units:
            totalHealth += unit.health

and i just attack ammediatly please help me.

@AnSeDra (twenty characters)

Can you send me the full code, please?

# Attack when your soldiers' total health is greater
# than the ogres' total health

# This function return the sum of all the units' health.
def sumHealth(units):
    totalHealth = 0
    # Complete this function:
    for unit in units:
        totalHealth += unit.Health
    return totalHealth

while True:
    friends = hero.findFriends()
    enemies = hero.findEnemies()
    # Get the total health of your soldiers and the ogres.
    if sumHealth(friends) <= sumHealth(enemies):
        hero.say("Wait")
    # Say "Attack" when your side has more total health.
    else:
        hero.say("ATTACK!!!")

sorry

no it dosent i dont know why

Put unit.health. Capital H is ruining your code. Does it work now?

it is working now thank you for the help.

No problem! Next time be more careful with the capital letters. Units have the property health, not Health.