CodeAgeBy Sitezack
Python for Builders — Level 3Decisions and repetitions0 XP
Chapter progress0/6

Lesson 4 of 7

while: repeat as long as…

while repeats a block as long as its condition is true. Careful: something must change inside the loop, or it never stops!

It's perfect for a video game battle: "while there's energy left, keep going".

lives = 3
while lives > 0:
    lives = lives - 1
print("Done!")

🎯 Your mission

Your shield has energy = 10. Each round it loses 3 points. Count the rounds with rounds (starting at 0): while energy > 0, subtract 3 from energy and add 1 to rounds. Print rounds.

PRO lesson

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

Discover PRO