Bird
0
0

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

easy📝 Syntax Q3 of 15
Python - While Loop
Which of the following is the correct way 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: Recall Python syntax

    Python uses a colon and indentation to define blocks.
  2. Step 2: Analyze options

    while x > 0: print(x) uses a colon and indented block, which is correct.
  3. Final Answer:

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

    Colon and indentation required [OK]
Quick Trick: Use colon and indent code inside while loops [OK]
Common Mistakes:
MISTAKES
  • Omitting the colon after the while condition
  • Using braces instead of indentation
  • Trying to write while loop in one line without colon

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes