AlexeySapsay / Python_solution_CodeCombat_2018

In that repository I will post my sollution for codecombat.com games for study Python
1 stars 0 forks source link

Brittle Morale #162

Closed AlexeySapsay closed 6 years ago

AlexeySapsay commented 6 years ago
# Follow me on youtube  channel Phy Tu
# Help with programming on Python, school math, physics
# https://www.youtube.com/channel/UCP5ycahCEZ24qmRRgNnko5Q

# You have one arrow. Make it count!

# This should return the enemy with the most health.
def findStrongestEnemy(enemies):
    strongest = None
    strongestHealth = 0
    enemyIndex = 0
    # While enemyIndex is less than the length of enemies:
    for enemy in enemies:
        # Set an enemy variable to enemies[enemyIndex]
        enemies[enemyIndex]=enemy
        # If enemy.health is greater than strongestHealth
        if (enemy.health > strongestHealth):
            # Set `strongest` to enemy
            # Set strongestHealth to enemy.health
            strongest=enemy
            strongestHealth=enemy.health
        # Increment enemyIndex
        enemyIndex+=1

    return strongest

enemies = hero.findEnemies()
leader = findStrongestEnemy(enemies)
if leader:
    hero.say(leader)