Lab 7 reference, Summit Gear AR in Python

Keep this open beside your Lab 7 notebook. Colab cannot show code in color; this page can.

Every Lab 7 function's specification in one place. The notebook is where you write them, and the Final check cell at the bottom of the notebook tells you which ones are done. The grader also runs tests you cannot see, like boundary values, an empty list, and text where a number should be. So write the rule, not the example.

What a complete function looks like

This one is not in the lab; it is here to show the standard. Each lab function is graded on three things:

def discount_amount(price, discount_rate):
    """Return the dollar discount on a price, given the rate as a decimal."""
    discount = price * discount_rate
    return discount

Clear names for the inputs and variables, such as discount_rate instead of x, make the function easier to read when you come back to it next week, but names are not part of the points.

The twelve functions

Each stub gives you the def line, an empty docstring, and return None. Keep the def line exactly as given: the grader calls your functions by name.

1. is_number(value) Part 1

Returns True if the value is an int or a float, and False otherwise. Example: is_number(5) returns True; is_number("5") returns False. Excel: =ISNUMBER(A2).
def is_number(value):
    """ """
    return None

2. aging_bucket(days_past_due) Part 1

Returns the Week 3 aging label for a number of days past due, exactly one of "Current", "1-30", "31-60", "61-90", "Over 90". Zero or fewer days is "Current": due today counts as current, the same rule as Week 3. Boundaries: 30 is "1-30", 31 starts "31-60", 90 is "61-90", 91 is "Over 90". Example: aging_bucket(45) returns "31-60".
def aging_bucket(days_past_due):
    """ """
    return None

3. running_total(amounts) Part 1

Returns the total of a list of numbers, built with a for loop and +=, not sum(). Example: running_total([10, 20, 30]) returns 60. An empty list returns 0, not None.
def running_total(amounts):
    """ """
    return None

4. line_total(qty, price) Part 1

Returns the line amount: quantity times unit price. Example: line_total(2, 600.0) returns 1200.0. Excel: =B2*C2.
def line_total(qty, price):
    """ """
    return None

5. amount_with_tax(amount, tax_rate) Part 1

Returns the amount grossed up by a tax rate given as a decimal, so 0.0725 is 7.25 percent. Example: amount_with_tax(100, 0.0725) returns 107.25.
def amount_with_tax(amount, tax_rate):
    """ """
    return None

6. grand_total(pairs) Part 1

Returns the total of line_total(qty, price) over a list of (qty, price) tuples. It calls your own line_total. Example: grand_total([(2, 10.0), (3, 5.0)]) returns 35.0.
def grand_total(pairs):
    """ """
    return None

7. total_amount(df) Part 1

Returns the sum of the amount column of an invoices DataFrame. Example: total_amount(sample_ar) returns 12200.0. Excel: =SUM() down the column.
def total_amount(df):
    """ """
    return None

8. safe_line_total(qty, price) Part 1

Returns quantity times price when both are numbers, and None when either is not. Example: safe_line_total(7, 12.5) returns 87.5; safe_line_total("oops", 5) returns None. Excel: a formula wrapped in =IFERROR().
def safe_line_total(qty, price):
    """ """
    return None

9. large_invoices(df, threshold) Part 2

Returns a DataFrame of only the rows whose amount is strictly greater than threshold. Example: large_invoices(invoices, 10000) returns the invoices over 10,000. The boolean mask from the pandas bridge trainer does this. Excel: AutoFilter, Number Filters, Greater Than.
def large_invoices(df, threshold):
    """ """
    return None

10. total_by_segment(df) Part 2

Returns the total amount per segment of a merged invoices DataFrame, as a Series indexed by segment. Excel: a PivotTable with segment in Rows and Sum of amount in Values.
def total_by_segment(df):
    """ """
    return None

11. open_balances(invoices, payments) Part 3, harder

Returns the invoices that still have money owed. Add total_paid, the sum of that invoice's payments, which is 0 where there are none. Add balance, which is amount minus total_paid. Keep only the rows with balance greater than 0. An overpaid invoice has a negative balance and is not owed. This is the Week 3 open-invoice rule, now in pandas. Check: on the Summit Gear ledger it returns 1,404 invoices with $7,656,873.45 open, the same totals as your Week 3 homework.
def open_balances(invoices, payments):
    """ """
    return None

12. aging_summary(open_df, as_of) Part 3, harder

Returns a DataFrame with one row per aging label, in the order Current, 1-30, 31-60, 61-90, Over 90, and two columns: invoice_count and total_balance, rounded to cents. Days past due is as_of minus due_date, in days. Every label appears even when its count is 0. It reuses your aging_bucket. Check: as of 2026-04-30 the counts add to 1,404 and Current is 587, your Week 3 numbers.
def aging_summary(open_df, as_of):
    """ """
    return None

Tie your aging out to Week 3

Part 3 rebuilds the aging you built in SQL in Week 3: open balances as of 2026-04-30, five buckets. Two independent tools agreeing is how you know both are right. Open the Week 3 SQL workbench, run your own Week 3 aging query, and compare its five rows with your aging_summary, bucket by bucket. This step is not graded. If a bucket is off, look first at your aging_bucket boundaries and at how you computed days past due.

The Excel move behind each one

ExcelPython ideaLab function
a named formula like =B2*C2def with arguments and a returnline_total, amount_with_tax
=ISNUMBER(), =IFERROR()isinstance() and a guard that returns Noneis_number, safe_line_total
a nested IFan if / elif / else ladderaging_bucket
a running-total columnan accumulator and += in a for looprunning_total, grand_total
=SUM() down a columna column method on the DataFrametotal_amount
AutoFiltera boolean masklarge_invoices
a PivotTablegroupby, then a column, then an aggregatetotal_by_segment, aging_summary
XLOOKUP down the whole tablea left merge, then check the row countopen_balances
Remember: do the work in the notebook. Try each function yourself first, and use AI to explain an idea or an error, not to hand you a line you cannot read back.

Week 7 of ACCTG 6155, MAcc Analytics, Fall 2026. Code colorized with highlight.js.