✕ Close
← Project: Guess the Number

Level 5 · Lesson 42: Practice: little programs

Level 5 test: Loop Master →
PRACTICE
Little programs
Decisions, loops, lists and functions, mixed.
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 42: Practice: little programs

Level 5, Python Thinks and Repeats. Decisions, loops, lists and functions, mixed. It follows lesson 41, Project: Guess the Number. Next comes lesson 43, Level 5 test: Loop Master.

What the lesson explains

Little programs. Decisions, loops, lists and functions, mixed.

What you do first

One after another. Print the even numbers 2, 4, 6, 8. One way to write it: for n in range(2, 10, 2): / print(n). It prints: 2 / 4 / 6 / 8.

What you practise

Mixed, "One after another": Print the even numbers 2, 4, 6, 8. One way to write it: for n in range(2, 10, 2): / print(n). It prints: 2 / 4 / 6 / 8. Then: Print how many scores there are. The editor opens with: scores = [3, 9, 4, 7]. One way to write it: scores = [3, 9, 4, 7] / print(len(scores)). It prints: 4. Then: Print the biggest score. The editor opens with: scores = [3, 9, 4, 7]. One way to write it: scores = [3, 9, 4, 7] / print(max(scores)). It prints: 9. Then: Print Even or Odd for 7. The editor opens with: n = 7. One way to write it: n = 7 / if n % 2 == 0: / print("Even") / else: / print("Odd"). It prints: Odd.

Challenge, "The total": Add up a list with a function and a loop. One way to write it: def total(nums): / t = 0 / for n in nums: / t = t + n / return t / / print(total([5, 10, 15])). It prints: 30.

What PlayBuddy and PlayType say

PlayType: "Practice time! Little programs, one after another."

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.

A green ring shows where to click the first time. After that you do it on your own, and if you slip twice the ring comes back.

Stars

The lesson has 5 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.