Bird
0
0

Which of the following is the correct syntax to loop exactly 5 times using range()?

easy📝 Syntax Q3 of 15
Python - For Loop
Which of the following is the correct syntax to loop exactly 5 times using range()?
Afor i in range(0, 6):
Bfor i in range(1, 5):
Cfor i in range(5):
Dfor i in range(5, 9):
Step-by-Step Solution
Solution:
  1. Step 1: Understand range(n) loops n times

    range(5) generates 0,1,2,3,4 which is 5 iterations.
  2. Step 2: Check other options

    for i in range(1, 5): loops 4 times (1 to 4)
    for i in range(0, 6): loops 6 times (0 to 5)
    for i in range(5, 9): loops 4 times (5 to 8)
  3. Final Answer:

    for i in range(5): -> Option C
  4. Quick Check:

    range(n) loops n times starting at 0 [OK]
Quick Trick: range(n) loops from 0 to n-1 exactly n times [OK]
Common Mistakes:
MISTAKES
  • Using wrong start or stop
  • Counting iterations incorrectly
  • Starting loop at 1 by default

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes