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.
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
def line is kept exactly as the lab gives it, and return None is replaced with a real body,def saying what it returns,return, since a function that only prints its answer returns None.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.
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.
is_number(value) Part 1True 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
aging_bucket(days_past_due) Part 1"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
running_total(amounts) Part 1for 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
line_total(qty, price) Part 1line_total(2, 600.0) returns 1200.0. Excel: =B2*C2.def line_total(qty, price):
""" """
return None
amount_with_tax(amount, tax_rate) Part 10.0725 is 7.25 percent. Example: amount_with_tax(100, 0.0725) returns 107.25.def amount_with_tax(amount, tax_rate):
""" """
return None
grand_total(pairs) Part 1line_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
total_amount(df) Part 1amount column of an invoices DataFrame. Example: total_amount(sample_ar) returns 12200.0. Excel: =SUM() down the column.def total_amount(df):
""" """
return None
safe_line_total(qty, price) Part 1None 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
large_invoices(df, threshold) Part 2amount 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
total_by_segment(df) Part 2amount 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
open_balances(invoices, payments) Part 3, hardertotal_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
aging_summary(open_df, as_of) Part 3, harderCurrent, 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
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.
| Excel | Python idea | Lab function |
|---|---|---|
a named formula like =B2*C2 | def with arguments and a return | line_total, amount_with_tax |
=ISNUMBER(), =IFERROR() | isinstance() and a guard that returns None | is_number, safe_line_total |
a nested IF | an if / elif / else ladder | aging_bucket |
| a running-total column | an accumulator and += in a for loop | running_total, grand_total |
=SUM() down a column | a column method on the DataFrame | total_amount |
| AutoFilter | a boolean mask | large_invoices |
| a PivotTable | groupby, then a column, then an aggregate | total_by_segment, aging_summary |
XLOOKUP down the whole table | a left merge, then check the row count | open_balances |
Week 7 of ACCTG 6155, MAcc Analytics, Fall 2026. Code colorized with highlight.js.