← Learn to Code — Python for Beginners
Module · Making Decisions
if, elif, else
Now let's use those True/False comparisons to make a program branch.
marks = 78
if marks >= 90:
print("Excellent")
elif marks >= 60:
print("Good")
else:
print("Keep practising")
A few rules Python is strict about:
- The line with
ifends in a colon: - Whatever runs "inside" the if must be indented (usually 4 spaces) — Python uses indentation to know what belongs together
elifmeans "else if" — check another condition if the first wasn't trueelsecatches everything else
Try it: change the marks value below and run it a few times to see different outputs.