Conditional Statements and Decision Making¶
Teach Python how to choose the next action when business rules, thresholds, or changing inputs demand different outcomes.
This notebook builds directly on variables, data types, and operators. Once you can store values and compare them, the next step is deciding what should happen when a condition is true, false, or only partly true.

Control flow lets a program make decisions. Instead of running every line the same way every time, Python can evaluate conditions and choose what should happen next.
This matters whenever a rule changes the outcome: approve or reject a discount, flag risky transactions, label customers, or decide whether a model score is acceptable.
Why This Matters¶
Discount approval, stock alerts, order routing, and fraud checks all depend on conditions that change the next action.
Prediction scores often lead to branches such as accept, review, escalate, or reject.
Conditionals make decisions explicit. That clarity matters when code needs to be tested, explained, and changed later.
Concept Explanation¶
Conditionals are useful whenever different situations require different actions. A conditional statement asks a question that evaluates to True or False, then runs the branch that matches the answer.
For example, you might:
approve or reject a discount
classify a customer as active or inactive
decide whether inventory is low
determine whether a model score should trigger review
Reading the logic
Python checks whether
sales >= 10000if the answer is
True, the first branch runsotherwise, the
elsebranch runs
Worked Example: Order Review Workflow¶
A business might route orders differently depending on their value. Small orders can be processed normally, medium ones may need an extra check, and very large ones may need manual approval.
Why elif matters
elif lets you test another condition only when the earlier one was not true. That helps you express ranked decision rules without writing separate disconnected if statements.
Quick Quiz¶
When should you use an if statement?¶
import, not if.risk_score = 82
if risk_score >= 85:
print("Escalate for immediate review")
elif risk_score >= 60:
print("Queue for analyst review")
else:
print("Approve automatically")Queue for analyst review
Guided Exercise¶
Use conditionals to design a simple loyalty decision rule for a store.
purchase_total = 920
is_member = True
# TODO: if the customer is a member and spends at least 900, print "VIP reward"
# TODO: otherwise if the customer is a member, print "Member discount"
# TODO: otherwise print "Standard pricing"Hint
Start by checking the most specific case first. If you reverse the order, a broader condition may capture the case too early.
One possible solution
purchase_total = 920
is_member = True
if is_member and purchase_total >= 900:
print("VIP reward")
elif is_member:
print("Member discount")
else:
print("Standard pricing")Quick Summary¶
Key Takeaways
conditionals help programs choose between actions instead of running one fixed path
if,elif, andelselet you express ranked decision rules clearlycomparisons produce boolean results that drive branch selection
indentation tells Python which lines belong to each branch
The next notebook extends this idea by showing how Python can repeat a decision or action across many values with loops.
Interactive Code¶
Expected output
High performanceExpected output
Low stockGuided Practice¶
Which keyword starts a second condition after if?¶
elif adds another conditional branch.then in if statements.What prints when inventory = 5 in the example above?¶
Extension Prompt¶
Write a conditional that checks a model confidence score and prints one of three outcomes: "accept", "review", or "reject". Keep the thresholds simple now. The next notebook on loops will show how to apply the same rule across many records instead of just one value.