"""monthly_report.py — generate the monthly sales report.
Usage: python monthly_report.py
"""
# ---- 1. Imports (standard library first, then third-party, then your own) ----
import os
from datetime import date
import pandas as pd
from helpers import clean_email
# ---- 2. Constants ----
INPUT_FILE = "sales_raw.csv"
OUTPUT_FILE = "sales_clean.xlsx"
TAX_RATE = 0.08
# ---- 3. Functions ----
def load(path):
return pd.read_csv(path)
def clean(df):
df["email"] = df["email"].apply(clean_email)
df["total"] = df["price"] * (1 + TAX_RATE)
return df
def save(df, path):
df.to_excel(path, index=False)
def main():
df = load(INPUT_FILE)
df = clean(df)
save(df, OUTPUT_FILE)
print(f"Wrote {len(df)} rows to {OUTPUT_FILE}")
# ---- 4. The "run me" line ----
if __name__ == "__main__":
main()
if __name__ == "__main__" thing?It's the line that says: "Run main() only if I was launched directly, not when someone imports me from another file."
Why it matters: if you put loose code at the bottom of the file, that code runs even when you just import the file from somewhere else. The if __name__ idiom prevents that.
clean_emails(df). "Read the input file" → load(path).
main() → if __name__ == "__main__".if __name__ guard stops your main() from running on import.Take the tip-calculator script you wrote in Module 3 and split it into three functions: get_inputs(), compute(bill, tip_pct, people), and print_results(...). Call them from main().