0%
⭐ 0 XPPractice
Pack 1 · Challenge 2 of 5 · 10 XP · ⏱ 4 min

Even Steven

2️⃣ % gives the remainder after dividing. Even numbers have no remainder when you divide by 2, so n % 2 == 0 is True for them.

print(7 % 2)
print(8 % 2)
1
0

You can also step through range() two at a time. Either way works.

Instructions

  1. Use a for loop (don't type the numbers by hand).
  2. Print every even number from 2 to 20, one per line.
💡 Hint

for n in range(1, 21): then if n % 2 == 0: print(n). Or step two at a time with range(2, 21, 2).

Ask the community

bot.py
Terminal
← BackNext →

Python Warm-ups

All practice packs

Talk it out

  1. Read the instruction with the ✗ out loud.
  2. Say what your code does, line by line, as if to a friend.
  3. Find the line where what it does and what you want split apart.
  4. Press Run and read the terminal. Is that what you expected?
  5. Still stuck? Press Ask Pip why, or peek at the solution.
  6. Or ask on the community help board: say which quest, and paste your code.
New badge!

Your bot just got a new part. See it on the quest map.

Name your bot

It levels up as you play, and gets a new part with every chapter.