Here is my current code for the level :
# Attack when your soldiers' total health is greater # than the ogres' total health # Write a function that takes an array of units as input # And returns the sum of all the units' health def sumHealth(): totalHealth = 0 unitIndex = 0 while unitIndex < len(): currentUnit = totalHealth = totalHealth + currentUnit.health return totalHealth while True: friends = hero.findFriends() enemies = hero.findEnemies() # Get the total health of your soldiers and the ogres. # Say "Attack" when your side has more total health.
My problem here is that I don’t know what to put in the function between paranthese for the len(): part. I know how to do the sumHealth functions for a particular array, for example I’d know how to find the totalHealth of the enemies array by itself, but I would need 2 seperate functions to find the totalHealth of each of the arrays, one for each. Could anybody help with explaining how I would go about doing this for finding the totalHealth using only the one function (as I expect is wanted, I think they are wanting you to use one function for both arrays). Also, how would I do the “get the total health of your soldiers and the ogres” part?