Bird
0
0

You want to write a program that prints numbers 1 to 5, but skips number 3. Which code correctly shows how Python executes this?

hard📝 Application Q15 of 15
Python - Basics and Execution Environment
You want to write a program that prints numbers 1 to 5, but skips number 3. Which code correctly shows how Python executes this?
Afor i in range(1,6): if i == 3: pass print(i)
Bfor i in range(1,5): if i == 3: break print(i)
Cfor i in range(1,6): if i != 3: break print(i)
Dfor i in range(1,6): if i == 3: continue print(i)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the goal and loop behavior

    We want to print numbers 1 to 5 but skip printing 3. Using continue skips the current loop iteration.
  2. Step 2: Analyze each option

    for i in range(1,6): if i == 3: continue print(i) uses continue to skip printing 3 and prints all others. Others either break early or print 3.
  3. Final Answer:

    for i in range(1,6): if i == 3: continue print(i) -> Option D
  4. Quick Check:

    continue skips printing 3 [OK]
Quick Trick: Use continue to skip unwanted loop steps [OK]
Common Mistakes:
MISTAKES
  • Using break which stops the loop entirely
  • Using pass which does nothing to skip printing
  • Incorrect range limits causing missing numbers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes