if / elif / else
score = 72
if score >= 70:
print("First Class")
elif score >= 60:
print("Second Class Upper")
else:
print("Keep practicing")
Python uses indentation, not braces, to mark a block -- every line inside the if must be indented the same amount (4 spaces is the convention).
for loops
for i in range(5):
print(i)
range(5) produces 0, 1, 2, 3, 4 -- 5 numbers starting at 0, stopping before 5.
while loops
count = 0
while count < 3:
print(count)
count = count + 1
break and continue
for i in range(10):
if i == 5:
break # exits the loop entirely
if i % 2 == 0:
continue # skips to the next iteration
print(i)
Why This Matters for Your Exams
Indentation is not a style choice in Python -- it's the syntax. Mixing tabs and spaces, or indenting inconsistently, causes an IndentationError that stops your program from running at all.
Try it yourself
lock
Real-time practice is a paid add-on
Reading units and the practice quiz are free. Pay once to unlock running real code for PYTHON.

