Drill

ProblemsPython › games

Calculate combat damage

easygamesPython

A simple combat system subtracts the defender's rating from the attacker's, but damage never drops below zero.

combat_round(attack: int, defense: int) → int

Solve it in the editor →

Where you start

def combat_round(attack: int, defense: int) -> int:
    

Worked examples

CallResult
combat_round(10, 5)5
combat_round(3, 7)0
combat_round(0, 0)0
combat_round(100, 100)0

Hint

Subtract, then clamp.

Reference solution in Python
def combat_round(attack: int, defense: int) -> int:
    return max(0, attack - defense)

The same problem in another language

More games problems in Python