# Fair Battle/ Python/ Help \[Solved\]

**URL:** <https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745>\
**Category:** Level Help\
**Created:** [March 4, 2021, 5:57pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745 "2021-03-04T17:57:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)\
**Post date:** [March 4, 2021, 5:57pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/1 "2021-03-04T17:57:32Z")

</div>

My person either isn’t defining the health or is choosing not to say it

```python
while True:
    friends = hero.findFriends()
    enemies = hero.findEnemies()
    # Calculate and compare the total health of your soldiers and the ogres.
    def healthSum(enemies):
        enemiesIndex = 0
        health = 0
        while enemiesIndex < enemies.len:
            enemies = enemies[enemiesIndex]
            enemiesIndex +=1
            health += enemies.health
        return health    
    
    def healthSum(friends):
        friendsIndex = 0
        health = 0
        while friendsIndex < friends.len:
            friends = friends[friendsIndex]
            friendsIndex +=1
            health += friends.health
        return health 
    
    if healthSum(friends) > healthSum(enemies):
        hero.say("Attack")
# Say "Attack" when you are ready.

```

---

<div class="post-metadata">

**Author:** ![Ashmit\_Singh](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Ashmit\_Singh](https://discourse.codecombat.com/u/Ashmit_Singh)\
**Post date:** [March 4, 2021, 6:02pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/2 "2021-03-04T18:02:16Z")

</div>

Which sense stone do you have? i used quartz and later the sapphire one.

---

<div class="post-metadata">

**Author:** ![Ashmit\_Singh](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Ashmit\_Singh](https://discourse.codecombat.com/u/Ashmit_Singh)\
**Post date:** [March 4, 2021, 6:03pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/3 "2021-03-04T18:03:04Z")

</div>

name the functions differently please, thats all that is wrong

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [March 4, 2021, 6:03pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/4 "2021-03-04T18:03:38Z")

</div>

That doesn’t matter.

---

<div class="post-metadata">

**Author:** ![Ashmit\_Singh](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Ashmit\_Singh](https://discourse.codecombat.com/u/Ashmit_Singh)\
**Post date:** [March 4, 2021, 6:07pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/5 "2021-03-04T18:07:06Z")

</div>

does, healthSum doesnt know which one you are talking about, and the thing in the brackets has no value, its just an internal variable.  
use:

```python
while True:
    friends = hero.findFriends()
    enemies = hero.findEnemies()
    # Calculate and compare the total health of your soldiers and the ogres.
    def healthSumBad(enemies):
        enemiesIndex = 0
        health = 0
        while enemiesIndex < enemies.len:
            enemies = enemies[enemiesIndex]
            enemiesIndex +=1
            health += enemies.health
        return health    
    
    def healthSumGood(friends):
        friendsIndex = 0
        health = 0
        while friendsIndex < friends.len:
            friends = friends[friendsIndex]
            friendsIndex +=1
            health += friends.health
        return health 
    
    if healthSumGood(friends) > healthSumBad(enemies):
        hero.say("Attack")
# Say "Attack" when you are ready.

```

---

<div class="post-metadata">

**Author:** ![Ashmit\_Singh](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Ashmit\_Singh](https://discourse.codecombat.com/u/Ashmit_Singh)\
**Post date:** [March 4, 2021, 6:07pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/6 "2021-03-04T18:07:37Z")

</div>

i’ve fixed it, ill edit it out if its a working piece of code

---

<div class="post-metadata">

**Author:** ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)\
**Post date:** [March 4, 2021, 6:09pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/7 "2021-03-04T18:09:43Z")

</div>

Like this? Its still not working

```python
while True:
    friends = hero.findFriends()
    enemies = hero.findEnemies()
    # Calculate and compare the total health of your soldiers and the ogres.
    def healthSumEnemy(enemies):
        enemiesIndex = 0
        health = 0
        while enemiesIndex < enemies.len:
            enemies = enemies[enemiesIndex]
            enemiesIndex +=1
            health += enemies.health
        return health    
    
    def healthSumFreind(friends):
        friendsIndex = 0
        health = 0
        while friendsIndex < friends.len:
            friends = friends[friendsIndex]
            friendsIndex +=1
            health += friends.health
        return health 
    
    if healthSumFreind(friends) > healthSumEnemy(enemies):
        hero.say("Attack")
# Say "Attack" when you are ready.

```

---

<div class="post-metadata">

**Author:** ![Ashmit\_Singh](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Ashmit\_Singh](https://discourse.codecombat.com/u/Ashmit_Singh)\
**Post date:** [March 4, 2021, 6:12pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/8 "2021-03-04T18:12:55Z")

</div>

Yeah basically, mabye @Rachel699 could help, or another experienced player  
(i’m a veteran but im still on cloudrip and i suck)

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [March 4, 2021, 6:30pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/9 "2021-03-04T18:30:43Z")

</div>

maybe put this in a loop

> [@Some\_Guy](#):
>
> ```python
> if healthSumFreind(friends) > healthSumEnemy(enemies):
> hero.say("Attack")
> 
> ```

---

<div class="post-metadata">

**Author:** ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)\
**Post date:** [March 4, 2021, 6:37pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/10 "2021-03-04T18:37:59Z")

</div>

Do you mean in a different while loop or the same on the rest is

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [March 4, 2021, 6:39pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/11 "2021-03-04T18:39:04Z")

</div>

so just put that in this `while True:`

---

<div class="post-metadata">

**Author:** ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)\
**Post date:** [March 4, 2021, 6:39pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/12 "2021-03-04T18:39:50Z")

</div>

so like this?

```python
while True:
    friends = hero.findFriends()
    enemies = hero.findEnemies()
    # Calculate and compare the total health of your soldiers and the ogres.
    def healthSumEnemy(enemies):
        enemiesIndex = 0
        health = 0
        while enemiesIndex < enemies.len:
            enemies = enemies[enemiesIndex]
            enemiesIndex +=1
            health += enemies.health
        return health    
    
    def healthSumFreind(friends):
        friendsIndex = 0
        health = 0
        while friendsIndex < friends.len:
            friends = friends[friendsIndex]
            friendsIndex +=1
            health += friends.health
        return health 
    
    if healthSumFreind(friends) > healthSumEnemy(enemies):
        hero.say("Attack")

```

its still not working

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [March 4, 2021, 6:40pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/13 "2021-03-04T18:40:39Z")

</div>

No just this part, thats all.

> [@Some\_Guy](#):
>
> ```python
> if healthSumFreind(friends) > healthSumEnemy(enemies):
> hero.say("Attack")
> 
> ```

---

<div class="post-metadata">

**Author:** ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)\
**Post date:** [March 4, 2021, 6:42pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/14 "2021-03-04T18:42:44Z")

</div>

So like this? @milton.jinich

```python
def healthSumEnemy(enemies):
    enemiesIndex = 0
    health = 0
    while enemiesIndex < enemies.len:
        enemies = enemies[enemiesIndex]
        enemiesIndex +=1
        health += enemies.health
    return health    
    
def healthSumFreind(friends):
    friendsIndex = 0
    health = 0
    while friendsIndex < friends.len:
        friends = friends[friendsIndex]
        friendsIndex +=1
        health += friends.health
    return health 
while True:
    if healthSumFreind(friends) > healthSumEnemy(enemies):
        hero.say("Attack")
# Say "Attack" when you are ready.

```

Its still not working

---

<div class="post-metadata">

**Author:** ![098765432123](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/098765432123/32/25850_2.png) [@098765432123](https://discourse.codecombat.com/u/098765432123)\
**Post date:** [March 4, 2021, 7:00pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/15 "2021-03-04T19:00:21Z")

</div>

It looks like you are not attacking look here

> [@Some\_Guy](#):
>
> `# Say "Attack" when you are ready.`

There is nothing below it so how do you plan to attack?

---

<div class="post-metadata">

**Author:** ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)\
**Post date:** [March 4, 2021, 7:01pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/16 "2021-03-04T19:01:38Z")

</div>

Look above `# Say "Attack" when you are ready.`

---

<div class="post-metadata">

**Author:** ![098765432123](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/098765432123/32/25850_2.png) [@098765432123](https://discourse.codecombat.com/u/098765432123)\
**Post date:** [March 4, 2021, 7:03pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/17 "2021-03-04T19:03:14Z")

</div>

Can I please have a link to the level? and your stuff to so I can see what abilities you have are you a sub?

---

<div class="post-metadata">

**Author:** ![lukas31](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lukas31/32/22892_2.png) [@lukas31](https://discourse.codecombat.com/u/lukas31)\
**Post date:** [March 4, 2021, 9:49pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/18 "2021-03-04T21:49:14Z")

</div>

You need to write the code like this:

```python
enemy = enemies[enemiesIndex]
enemiesIndex += 1
health += enemy.health

```

It is just that you have 2 enemies lists/variable, and the code doesn’t know which one you are talking about. Do that to the friends function and you should be good. Hope this helps,  
Lukas

---

<div class="post-metadata">

**Author:** ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)\
**Post date:** [March 4, 2021, 10:55pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/19 "2021-03-04T22:55:58Z")

</div>

![Equipment](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/7/3/7374cbcadf27ac3af2848b8ab3c195584755800d.png)

```python
def healthSumEnemy(enemies):
    enemiesIndex = 0
    health = 0
    while enemiesIndex < enemies.len:
        enemies = enemies[enemiesIndex]
        enemiesIndex +=1
        health += enemies.health
    return health    
    
def healthSumFriend(friends):
    friendsIndex = 0
    health = 0
    while friendsIndex < friends.len:
        friends = friends[friendsIndex]
        friendsIndex +=1
        health += friends.health
    return health 
while True:
    if healthSumFriend(friends) > healthSumEnemy(enemies):
        hero.say("Attack")

```

[CodeCombat - Coding games to learn Python and JavaScript](https://codecombat.com/play/level/fair-battle)?

---

<div class="post-metadata">

**Author:** ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)\
**Post date:** [March 4, 2021, 10:58pm UTC](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745/20 "2021-03-04T22:58:13Z")

</div>

Like this?

```python
def healthSumEnemy(enemies):
    enemiesIndex = 0
    health = 0
    while enemiesIndex < enemies.len:
        enemy = enemies[enemiesIndex]
        enemiesIndex +=1
        health += enemy.health
    return health    
    

```

[Next page](https://discourse.codecombat.com/t/fair-battle-python-help-solved/27745.md?page=2)
