CodeAgeBy Sitezack
Final project: your text RPGYour choose-your-own adventure0 XP
Chapter progress0/6

Lesson 4 of 6

The battle loop

A battle is a while loop: while the monster has health points, your hero strikes.

Count the rounds in rounds — it tells you whether your hero is fast or needs training!

while monster_hp > 0:
    monster_hp = max(0, monster_hp - 5)
    rounds = rounds + 1

🎯 Your mission

A monster has monster_hp = 12 and your hero strikes with power = 5. With a while loop, strike until monster_hp drops to 0 (use max(0, …)) while counting the rounds in rounds (starting at 0). Print rounds.

PRO lesson

This advanced chapter is part of CodeAge PRO. Unlock it to keep your adventure going.

Discover PRO