Bird
0
0

Which of the following is the correct syntax to start a counter at 0 before a while loop?

easy📝 Syntax Q12 of 15
Python - While Loop

Which of the following is the correct syntax to start a counter at 0 before a while loop?

?
Acounter := 0
Bwhile counter = 0:
Ccounter == 0
Dcounter = 0
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct variable assignment

    To start a counter, assign 0 using a single equal sign: counter = 0.
  2. Step 2: Check other options for syntax errors

    while counter = 0: uses assignment in while condition (invalid), C uses comparison, D uses walrus operator incorrectly here.
  3. Final Answer:

    counter = 0 -> Option D
  4. Quick Check:

    Assign counter with = 0 before loop = A [OK]
Quick Trick: Use single = to assign counter before loop [OK]
Common Mistakes:
MISTAKES
  • Using == instead of = for assignment
  • Trying to assign inside while condition
  • Confusing walrus operator usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes