Bird
0
0

Which of the following is a syntax error in Python if-else statements?

easy📝 Syntax Q3 of 15
Python - Conditional Statements
Which of the following is a syntax error in Python if-else statements?
Aif x == 5: print('Five') else: print('Not five')
Bif x < 10: print('Less than ten') else: print('Ten or more')
Cif x != 0: print('Non-zero') else: print('Zero')
Dif x > 0 print('Positive') else: print('Non-positive')
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct if syntax

    Python requires a colon ':' after the if condition.
  2. Step 2: Check each option for missing colon

    if x > 0 print('Positive') else: print('Non-positive') misses the colon after 'if x > 0', causing syntax error.
  3. Final Answer:

    Missing colon after if condition causes syntax error. -> Option D
  4. Quick Check:

    Missing colon after if = syntax error [OK]
Quick Trick: Always put colon after if condition [OK]
Common Mistakes:
MISTAKES
  • Forgetting colon after if or else
  • Incorrect indentation after if or else

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes