✕ Close
← Practice: little programs

Level 5 · Lesson 43: Level 5 test: Loop Master

How the web works →
LEVEL 5 TEST
Loop Master
Everything from Level 5.
No hints this time. Read the red text if it appears.
press Enter ↵
🐍 main.py
Ctrl + Enter runs it too. Esc, then Tab, leaves the code.
Output

Press ▶ Run to see what your program does.

Lesson 43: Level 5 test: Loop Master

Level 5, Python Thinks and Repeats. if, loops, lists and functions, then a shopping list. It follows lesson 42, Practice: little programs. Next comes lesson 44, How the web works.

What the lesson explains

Loop Master. Everything from Level 5. No hints this time. Read the red text if it appears.

What you do first

Show what you know. Which line compares two values? The answer: "if a == b:".

The code on the screen

Loop Master. The editor shows 8 lines: def stars(n): / return "*" * n / / for i in range(1, 4): / if i % 2 == 1: / print(stars(i), "odd") / else: / print(stars(i), "even"). Run it, and it prints "* odd", "** even", "*** odd".

What you practise

Test, "Show what you know": Which line compares two values? The answer: "if a == b:". Then: Print 0, 1 and 2 with a for loop. One way to write it: for i in range(3): / print(i). It prints: 0 / 1 / 2. Then: colours = ["red", "blue"]. What is colours[1]? The answer: "blue". Then: Write half(n) that returns n / 2, and print half(9). One way to write it: def half(n): / return n / 2 / / print(half(9)). It prints: 4.5. Then: A while loop never stops. What is missing? The answer: "A line that changes the test".

Challenge, "Shopping list": Build a list and print each item. The editor opens with: shopping = []. One way to write it: shopping = [] / shopping.append("bread") / shopping.append("milk") / for item in shopping: / print(item). It prints: bread / milk.

Help in every lesson

Everything happens on a pretend computer in your browser, so nothing touches your real files. PlayBuddy and PlayType stand beside the board, cheer you on and say when it is your turn.

This is a test, so the green ring stays away: you show what you know on your own.

Stars

The lesson has 6 things to do. Up to one slip in ten gives three stars, up to one in four gives two, and finishing always gives at least one. Stars and progress are saved in this browser only; there is no account.

About DayOneCode

DayOneCode is an independent learning site, not affiliated with or endorsed by Anthropic. Claude and Claude Code are trademarks of Anthropic.