Module 03 — Branching and Control Flow#

Graduate MSBA Module Overview

In business analytics, data rarely tells a single story — it tells different stories depending on conditions. A customer either qualifies for a discount or does not. A transaction is either fraudulent or legitimate. Revenue either exceeds the target or falls short. Branching and control flow is how Python makes decisions based on conditions in data.

The if statement is the core tool: it evaluates whether a condition is true and executes different code depending on the result. Combined with elif and else, you can build decision trees that respond to any data scenario.


Course Connections#

Branching directly connects to the concept of inference — one of the four foundational programming principles in this course. Inference is about drawing conclusions from data, and branching is the mechanism that implements those conclusions in code. When you write a branching statement, you are encoding a business rule: if this condition holds, take this action. That is the essence of data-driven decision making.


Quick Code Example#

customer_name = 'Alice Johnson'
total_spent = 1257.30
purchase_count = 12
region = 'Northwest'

if total_spent >= 1000 and purchase_count >= 10:
    customer_tier = 'Platinum'
elif total_spent >= 500 or purchase_count >= 5:
    customer_tier = 'Gold'
else:
    customer_tier = 'Standard'

if region == 'Northwest':
    shipping_discount = 0.15
else:
    shipping_discount = 0.05

print('Customer:', customer_name)
print('Customer Tier:', customer_tier)
print('Shipping Discount:', str(shipping_discount * 100) + '%')

Expected Output:

Customer: Alice Johnson
Customer Tier: Platinum
Shipping Discount: 15%

Learning Progression#

PlatformWhat Students Will Do
NotebookLMExplore branching through business scenarios where decisions must be made based on data — customer segmentation, fraud detection, and pricing rules
Google ColabWrite and test branching logic in Python, seeing how conditions evaluate and how code paths change based on data values
ZybooksBuild fluency through structured exercises that reinforce conditional logic and comparison operators

Module Pages#

  • Concept → — Deep narrative on branching and business decision logic
  • Advanced → — Extended code example with multi-condition business rules
  • Notebook → — Jupyter notebook lab description