My code doesn’t seem to work though it worked a while ago so I changed it a bunch but it still won’t work because I don’t know what variable to use.
def sumHealth(enemies):
# Create a variable and set it to 0 to start the sum.
totalHealth = 0
# Initialize the loop index to 0
index = 0
# While index is less than the length of enemies array
while index < len(enemies):
# Add the current enemy's health to totalHealth
totalHealth = enemies[index].value
# Increment the index.
index += 1
return totalHealth
# 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.")