Bird
0
0

Which of the following is the correct syntax to increase a counter by 1 inside a while loop?

easy📝 Syntax Q3 of 15
Python - While Loop

Which of the following is the correct syntax to increase a counter by 1 inside a while loop?

Acounter = counter + 1
Bcounter ++
Ccounter += 2
Dcounter =+ 1
Step-by-Step Solution
Solution:
  1. Step 1: Review Python syntax for incrementing

    Python uses 'counter = counter + 1' or 'counter += 1' to increase by 1.
  2. Step 2: Check other options

    'counter ++' is invalid in Python; 'counter += 2' adds 2, not 1; 'counter =+ 1' is wrong syntax.
  3. Final Answer:

    counter = counter + 1 -> Option A
  4. Quick Check:

    Increment counter by 1 with 'counter = counter + 1' [OK]
Quick Trick: Use 'counter = counter + 1' to add one in Python [OK]
Common Mistakes:
MISTAKES
  • Using 'counter ++' like other languages
  • Adding wrong number
  • Typing '=+' instead of '+='

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes