CONDITIONALS · 8 MIN
If / Elif / Else
Conditionals let a program choose which block to run.
PYRA explains
- if checks a condition that is True or False.
- elif adds more checks, tested only if earlier ones were False.
- else runs when nothing above matched. Indentation defines each block.
Real world: A traffic light: green → go, yellow → slow, else → stop.
Code
marks = 72
if marks >= 90:
print("A")
elif marks >= 60:
print("B")
else:
print("C")Output ›
BTry it in the online compiler →Checkpoint quiz
If marks = 95, how many branches run?