Code Monsters Academy
Home › Course contents › Level 10: The Lazy Trick
for loops

Level 10: The Lazy Trick

Chapter 1 · Starter Village

To make the computer repeat the same thing, use for:

for i in range(3):
    attack()

It means: repeat the line below 3 times. To repeat a different number of times, change the number in range().

Two small rules: ① the first line ends with a colon : ② the line to repeat starts with 4 spaces (press Tab once).

GoalDefeat the Boulshell (60 HP). Rule: at most 2 lines of code.
TipDon't worry about i and in yet — just copy the pattern.
Starting code
# Use for to repeat attack(), in at most 2 lines of code
Practise this in the game
← Previous levelLevel 9: Keep GoingNext level →Level 11: Perfect Timing