logo

Sum Array

Create a combat function that takes the player's current health and the amount of damage received, and returns the player's new health. Health can't be less than 0.


My code:

def combat(health, damage):
    total = health - damage
    if total == 0:
        return None
    elif total < 0:
        return 0
    elif total > 0:
        return total
                     
                    


And that's the best solution among all users:

def combat(health, damage):
    return max(0, health-damage)