🔀Conditionals (if / elif / else) · Project
Make programs choose different paths — then build a Smart Quiz.
📖 Key concepts
- if runs code when a condition is True
- elif checks more conditions
- else is the fallback
- Indentation defines the block
💻 Try this code
score = int(input("Score (0-100)? "))
if score >= 90:
print("Grade A")
elif score >= 60:
print("Grade B")
else:
print("Keep practising!")👥 Learn it your way
🧒 Young Explorers
Conditionals are choose-your-own-adventure: different answers, different endings.
Make a mood program: ask 1–10 happiness and reply differently for low/mid/high.
💼 Professionals
Prefer early returns / guard clauses over deeply nested ifs in real code.
Classify a BMI value into Underweight/Normal/Overweight with clear thresholds.
Before machine learning, "AI" was largely rule-based — giant if/elif trees (expert systems). You’re building that classic foundation today.
Build a 5-question quiz. Ask questions with input(), check answers with if/elif, keep a score, and print a grade + encouraging message at the end. Pro stretch: add a timer or categories.
✅ Quick check
When does elif run?
When the previous if/elif was False and its own condition is True.
What defines a block in Python?
Indentation.