Calculate combat damage
A simple combat system subtracts the defender's rating from the attacker's, but damage never drops below zero.
- Damage equals attack minus defense.
- A negative result is clamped to zero.
combat_round(attack: int, defense: int) → int
Where you start
def combat_round(attack: int, defense: int) -> int:
Worked examples
| Call | Result |
|---|---|
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)