Programming Fundamentals · Lesson 05
Conditions and decisions
Use a true-or-false question to choose which instructions run.
A condition is an expression that evaluates to True or False. Compare two values with operators such as == for equality, < for less than, or >= for greater than or equal to.
An if statement checks a condition. When the condition is true, Python runs the indented lines beneath it. An else clause supplies a second path when the condition is false. End each branch heading with a colon and indent its instructions consistently.
Think of a workshop that has space for twelve people. A check before accepting another visitor keeps the group within that limit.
Read the example
registered = 11
capacity = 12
if registered < capacity:
print("A seat is available.")
else:
print("The workshop is full.")
A seat is available.
Eleven is less than twelve, so Python runs the first print call. Set registered to 12 and it will take the else branch. Testing the exact boundary catches an easy mistake.
Try it yourself
Write a condition that prints “Ready” when a battery level is at least 20, and “Charge first” otherwise. Test it at 19 and at 20.
Show a worked solution
battery = 20
if battery >= 20:
print("Ready")
else:
print("Charge first")
Check your understanding
Your lesson quiz
Answer all five questions. Score at least 4 out of 5 (80%) to pass. You can retry as often as you like.
Quiz progress is saved in this browser. View certificates →
Learn together
Was this lesson helpful?
Comments and reactions are not open yet.
Join the conversation
Ask a question or share what you learned. Your display name and comment will be public after review. Please leave out private information. How feedback is stored