Bird
0
0

Which of these is the correct way to write an if-else statement in Python?

easy📝 Conceptual Q2 of 15
Python - Conditional Statements
Which of these is the correct way to write an if-else statement in Python?
Aif x > 10 print('Big') else print('Small')
Bif x > 10: print('Big') else: print('Small')
Cif (x > 10) { print('Big') } else { print('Small') }
Dif x > 10 then print('Big') else print('Small')
Step-by-Step Solution
Solution:
  1. Step 1: Recall Python syntax for if-else

    Python uses a colon after the condition and indentation for blocks.
  2. Step 2: Check each option

    if x > 10: print('Big') else: print('Small') uses colons and indentation correctly; others use syntax from other languages or missing colons.
  3. Final Answer:

    Correct Python if-else syntax with colons and indentation. -> Option B
  4. Quick Check:

    Python if-else needs colon + indent [OK]
Quick Trick: Use colon and indent blocks in Python if-else [OK]
Common Mistakes:
MISTAKES
  • Using 'then' keyword like other languages
  • Using braces {} instead of indentation
  • Missing colons after if and else

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes