S
Seoffix.com
Sign In Get Pro Membership

Python Foundations

Conditions and Loops

Beginner Python 25 XP

Conditions and Loops

Use if to choose and for to repeat. The modulo operator % gives the remainder.

Example

for n in range(3):
    if n == 1:
        print("one")

Your task

Print only the even numbers from 0 to 4.

Hints

  1. Loop with range(5)
  2. Test i % 2 == 0
  3. Print inside the if block

Check your understanding

Answer every question to pass.
1. What does range(3) produce?

2. What does 7 % 2 evaluate to?

Your answer

This lesson is checked against the lesson rules. Your code is never run on our servers.

AI Code Explainer & Translator

Runs without any outside service.
 
Mark Complete & Earn XP
Earn 25 XP after you pass the quiz. Finish every lesson in the track to earn its certificate.
Sign in to earn XP