# [Solved] Gas Attack returning "0"

#1

I checked my code and I can’t find any errors, but it always tells the cannon to use 0 grams.
Here’s my code.

``````# Calculate the total health of all the ogres.

def sumHealth(enemies):
# Create a variable and set it to 0 to start the sum.
totalHealth = 0
# Initialize the loop index to 0
enemyIndex = 0
# While enemyIndex is less than the length of enemies array
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
# Add the current enemy's health to totalHealth
if enemy:
enemies[totalHealth] += enemy.health
# Increment enemyIndex by 1.
enemyIndex +=1

# Use the cannon to defeat the ogres.
cannon = hero.findNearest(hero.findFriends())
# The cannon can see through the walls.
enemies = cannon.findEnemies()
# Calculate the sum of the ogres' health.
ogreSummaryHealth = sumHealth(enemies)
hero.say("Use " + ogreSummaryHealth + " grams.")

``````

#2

That’s the problem. (20)

#3

When I looked at others posts in this topic, I saw that one person had the two mixed up, so that he was changing the enemy’s health, so I switched mine around because I was doing the same, but it still won’t work

#4

I removed the enemies and brackets from totalHealth and it worked fine.

#5

That’s what I meant… Do you know what the enemies and brackets are actually doing?