Case Study 3.1: Acme Corp — Building the Revenue Scorecard
The Context
After Chapter 2's setup session, Priya has Python running. Now she wants to do something real. Sandra mentioned in their last 1:1 that she'd love a "quick daily scorecard" — something she could read in 30 seconds to know how the business is doing.
Priya's first Python project: a script that calculates the core financial scorecard from raw numbers.
The Variables
Priya sits down with last Tuesday's numbers from Marcus's data export. She builds the script top-down: first, all the input variables; then calculations; then output.
"""
acme_scorecard.py
Daily revenue scorecard — Acme Corp
"""
# Sales data — Tuesday, March 19, 2024
date = "2024-03-19"
chicago_daily = 48_230.00
cincinnati_daily = 31_540.00
nashville_daily = 37_890.00
st_louis_daily = 28_110.00
# Prior Tuesday (comparison baseline)
chicago_prior = 44_100.00
cincinnati_prior = 33_200.00
nashville_prior = 35_100.00
st_louis_prior = 29_800.00
# Daily overhead allocation (monthly / 22 business days)
daily_overhead = 95_000 / 22
The Problem She Hits
Priya writes her first calculation:
total_daily = chicago_daily + cincinnati_daily + nashville_daily + st_louis_daily
She tests it. Correct: 145,770.00.
Then she tries to build the comparison label:
comparison = "vs. Prior Tue: " + (total_daily - total_prior_daily)
Python throws an error:
TypeError: can only concatenate str (not "float") to str
This is the type mismatch problem. She's trying to concatenate a string and a number. The fix:
# Option 1: Convert to string explicitly
comparison = "vs. Prior Tue: $" + str(total_daily - total_prior_daily)
# Option 2: f-string (cleaner)
variance = total_daily - total_prior_daily
comparison = f"vs. Prior Tue: ${variance:+,.0f}"
The + in the format spec {variance:+,.0f} adds an explicit + sign for positive numbers — so the output reads +$3,220` rather than just `$3,220. This is useful for variance displays.
The Completed Script
"""
acme_scorecard.py
Daily revenue scorecard — Acme Corp
"""
# ── TODAY'S DATA ──────────────────────────────────────────────────────────────
date = "2024-03-19"
chicago = 48_230.00
cincinnati = 31_540.00
nashville = 37_890.00
st_louis = 28_110.00
# ── PRIOR PERIOD ──────────────────────────────────────────────────────────────
chicago_prior = 44_100.00
cincinnati_prior = 33_200.00
nashville_prior = 35_100.00
st_louis_prior = 29_800.00
# ── OVERHEAD ──────────────────────────────────────────────────────────────────
daily_overhead = 95_000 / 22 # Monthly overhead / business days
# ── CALCULATIONS ─────────────────────────────────────────────────────────────
total = chicago + cincinnati + nashville + st_louis
total_prior = chicago_prior + cincinnati_prior + nashville_prior + st_louis_prior
variance = total - total_prior
variance_pct = variance / total_prior
# Gross margin estimate (company-wide average: 37%)
gross_profit = total * 0.37
operating_profit = gross_profit - daily_overhead
operating_margin = operating_profit / total
# ── FLAGS ─────────────────────────────────────────────────────────────────────
above_prior = variance > 0
healthy_day = operating_margin >= 0.15 # 15% minimum operating margin target
# ── OUTPUT ───────────────────────────────────────────────────────────────────
print(f"ACME SCORECARD — {date}")
print(f"{'='*40}")
print(f"Total Revenue: ${total:>12,.2f}")
print(f"Prior Period: ${total_prior:>12,.2f}")
print(f"Variance: ${variance:>+12,.2f} ({variance_pct:+.1%})")
print(f"")
print(f"Gross Profit (est): ${gross_profit:>12,.2f}")
print(f"Daily Overhead: ${daily_overhead:>12,.2f}")
print(f"Operating Profit: ${operating_profit:>12,.2f} ({operating_margin:.1%} margin)")
print(f"")
print(f"Status: {'↑ UP from prior' if above_prior else '↓ DOWN from prior'}")
print(f"Margin: {'✓ On track' if healthy_day else '✗ Below target'}")
Sandra's Reaction
Priya emails Sandra the output (pasted into the body of the email). Sandra replies in four minutes:
"This is exactly what I need every morning. Can you send this automatically?"
Chapter 19 (Email Automation) will answer that question. For now, Priya runs the script manually and pastes the output.
Discussion Questions
-
Priya hit the
TypeError: can only concatenate str (not "float") to strerror. This is one of the most common beginner errors in Python. What mental model does it reveal about how Python handles data types differently from Excel? -
The
{variance:+,.0f}format specifier displays an explicit+sign for positive numbers. When is this display convention useful in business reporting, and when might it be confusing? -
Priya's gross profit calculation uses a company-wide average COGS rate (37%) rather than the actual per-region rates from Case Study 3.1 in the main chapter. What are the trade-offs between this simplification and using actual per-region rates?
-
Sandra asks to have this sent automatically. Before automating anything, what error conditions should the script check for? What happens if one of the four regional numbers is missing or corrupted?