Bird
0
0

Which of the following is the correct syntax to write a while loop in Python?

easy📝 Syntax Q3 of 15
Python - While Loop

Which of the following is the correct syntax to write a while loop in Python?

?
Awhile x > 0 print(x)
Bwhile (x > 0) { print(x) }
Cwhile x > 0: print(x)
Dwhile x > 0 do: print(x)
Step-by-Step Solution
Solution:
  1. Step 1: Identify Python while loop syntax

    Python uses a colon after the condition and indentation for the loop body.
  2. Step 2: Compare options

    while x > 0: print(x) uses colon and indentation correctly; others use braces or missing colon.
  3. Final Answer:

    while x > 0: print(x) -> Option C
  4. Quick Check:

    Python while loop syntax = colon + indent [OK]
Quick Trick: Python loops need colon and indentation [OK]
Common Mistakes:
MISTAKES
  • Using braces instead of indentation
  • Omitting colon after condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes