All lessons
πŸ”€

If / Elif / Else

Teach your program how to make decisions.

Control Flow 15 min +50 XP

if / else

Run a block only when a condition is True; otherwise run the else block.

marks = 75
if marks >= 40:
    print("Pass")
else:
    print("Fail")

elif

elif checks additional conditions in order. The first True branch runs.

x = 0
if x > 0:
    print("positive")
elif x < 0:
    print("negative")
else:
    print("zero")

Comparison and logic

Use ==, !=, <, >, <=, >=, and combine with and / or / not.

Variables & Data Types