Bird
0
0

Find the error in this code:

medium📝 Debug Q14 of 15
Python - Conditional Statements
Find the error in this code:
num = 5
if num > 0
    print('Positive')
else:
    print('Non-positive')
AVariable 'num' is not defined
BWrong indentation on print statements
CMissing colon ':' after 'if num > 0' line
D'else' should be 'elif' here
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of if statement

    The if statement must end with a colon ':' to mark the start of the block.
  2. Step 2: Identify the missing colon

    The code misses the colon after 'if num > 0', causing a syntax error.
  3. Final Answer:

    Missing colon ':' after 'if num > 0' line -> Option C
  4. Quick Check:

    Colon needed after if condition [OK]
Quick Trick: Always put colon after if condition [OK]
Common Mistakes:
MISTAKES
  • Forgetting colon after if
  • Confusing else with elif
  • Incorrect indentation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes