Bird
0
0

You want to print only even numbers from 0 to 10 using a for loop. Which code correctly does this?

hard📝 Application Q8 of 15
Python - For Loop
You want to print only even numbers from 0 to 10 using a for loop. Which code correctly does this?
Afor i in range(1, 11): if i % 2 == 0: print(i)
Bfor i in range(0, 10, 2): print(i)
Cfor i in range(0, 11, 2): print(i)
Dfor i in range(10): if i % 2 == 0: print(i)
Step-by-Step Solution
Solution:
  1. Step 1: Understand range parameters

    range(start, stop, step) generates numbers from start up to stop-1, stepping by step.
  2. Step 2: Check which options print even numbers 0 to 10

    for i in range(0, 11, 2): print(i) uses range(0,11,2) which prints 0,2,4,6,8,10 correctly.
  3. Final Answer:

    for i in range(0, 11, 2):\n print(i) -> Option C
  4. Quick Check:

    range with step=2 prints even numbers [OK]
Quick Trick: Use step=2 in range to get even numbers [OK]
Common Mistakes:
MISTAKES
  • Off-by-one in range end
  • Starting range at 1
  • Not using step parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes