Bird
0
0

What is the output of this code?

medium📝 Predict Output Q13 of 15
Python - For Loop
What is the output of this code?
for i in range(2, 7, 2):
    print(i, end=' ')
A0 2 4 6
B2 3 4 5 6
C2 4 6 8
D2 4 6
Step-by-Step Solution
Solution:
  1. Step 1: Understand the range parameters

    range(2, 7, 2) starts at 2, stops before 7, stepping by 2.
  2. Step 2: List the numbers generated

    Numbers are 2, 4, 6.
  3. Final Answer:

    2 4 6 -> Option D
  4. Quick Check:

    range(2,7,2) = 2,4,6 [OK]
Quick Trick: Start, stop, step control numbers generated [OK]
Common Mistakes:
MISTAKES
  • Including 7 in output
  • Using wrong step size
  • Starting from 0 instead of 2

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes