# ［已解决］“公平之战”看了好几个帖子也没有解决，只好问下高人

``````def sumHealth(units):
totalHealth = 0
unitIndex = 0
unit = units[unitIndex]
while unitIndex < len(units):
totalHealth += unit.health
unitIndex +=1

while True:
friends = hero.findFriends()
enemies = hero.findEnemies()

friendHealth = sumHealth(friends)
enemyHealth = sumHealth(enemies)
hero.say("friends have " + friendHealth)
hero.say("enemies have " + enemyHealth)
if sumHealth(friends) > sumHealth(enemies):
hero.say("Attack")
``````

but the function is the same. how to define two functions? @MunkeyShynes

``````hero.say("friends have " + friendHealth)
hero.say("enemies have " + enemyHealth)
``````

`

``````def sumHealthFriend():
totalHealthFriend = 0
friendIndex = 0
friend = friends[friendIndex]
while friendIndex < len(friends):
totalHealthFriend += friend.health
friendIndex += 1

def sumHealthEnemy():
totalHealthEnemy = 0
enemyIndex = 0
enemy = enemies[enemyIndex]
while enemyIndex < len(enemies):
totalHealthEnemy += enemy.health
enemyIndex += 1
``````

`

ps：我看了一下，如果一开始friends是972（9个人，每人108），enemies是990（9个人，每人110），后面每次都是先来一个enemy，再来一个friend，这样的话，怎么可能打得过呀～

``````def sumHealthFriend():
totalHealthFriend = 0
friendIndex = 0
while friendIndex < len(friends):
friend = friends[friendIndex]
if friend:
totalHealthFriend += friend.health
friendIndex += 1