Yearly Earnings Report for a Rewards Membership Program
Math & Bit ManipulationAuto-graded · 13 test casesLast updated
Compute yearly revenue, cost, profit and per-member profit for a membership program from fees, monthly spend commission, and fixed and variable costs.
A rewards membership program wants a yearly financial summary. Write a function that takes the program's membership size and its pricing and cost figures, and returns the yearly totals.
Inputs
The parameters, in this order:
members(int): the number of members in the program.yearly_fee(float): the membership fee each member pays per year, in dollars.monthly_spend(float): the average amount each member spends per month, in dollars.commission_rate(float): the fraction of spending the program earns as commission, given as a decimal (for example,0.01means 1%).fixed_cost(float): the fixed cost of running the program per year, in dollars. It does not depend on the number of members.variable_cost_per_member(float): the cost per member per year, in dollars.months(int): the number of months in a year.
Rules
- Commission is earned on spending across the whole year, so annualize the monthly spend using
months. - Revenue per member per year is the yearly fee plus the yearly commission.
- Annual revenue is the revenue per member multiplied by
members. - Annual cost is
fixed_costplusvariable_cost_per_membermultiplied bymembers. - Annual profit is annual revenue minus annual cost. It may be negative, and the sign must be kept.
- Profit per member is annual profit divided by
members. Ifmembersis 0, profit per member is0.0.
Output
Return a dictionary with exactly these four keys:
"annual_revenue": total revenue for the year."annual_cost": total cost for the year."annual_profit": revenue minus cost."profit_per_customer": annual profit divided by the number of members (0.0when there are no members).
Constraints
membersis a non-negative integer.- All monetary inputs are non-negative numbers.
commission_rateis a decimal fraction, not a percentage.monthsis a positive integer.- No rounding is required. Return the results of the arithmetic as described.
Examples
Example 1
Input: yearly_program_summary(2000000, 50, 500, 0.01, 250000000, 5, 12)
Output: {'annual_revenue': 220000000, 'annual_cost': 260000000, 'annual_profit': -40000000, 'profit_per_customer': -20}
Hints
Hint 1
Spend is given per month while the fee and the costs are per year. Convert the commission to a yearly figure first.
Hint 2
Work out revenue per member per year, then scale to the whole membership. Fixed cost is added once and must not be multiplied by the member count.
Hint 3
Profit can be negative, so keep the sign. Guard the per-member division for the case of zero members.
Worked solution
Easy Try it yourself first — then compare your approach, complexity and edge cases.
Approach
This is unit-aware arithmetic. The only trap is that spending is quoted per month while every other figure is per year.
- Annualize the commission:
monthly_spend * monthsgives yearly spend, and multiplying bycommission_rategives yearly commission per member. - Add the yearly fee to get revenue per member per year.
- Multiply by
membersto get annual revenue. - Annual cost is the fixed cost, charged once, plus the variable cost per member multiplied by
members. - Annual profit is revenue minus cost, and may be negative.
- Profit per member is the annual profit divided by
members, returning0.0whenmembersis 0 to avoid division by zero.
Why it is correct
Each quantity is computed directly from its definition, with all values converted to the same time unit (a year) before being combined. Fixed cost does not scale with membership, so it is added once, and variable cost scales linearly. Checking the sample: commission is 500 * 0.01 * 12 = 60 per member, so revenue per member is 110 and annual revenue is 220,000,000. Cost is 250,000,000 + 10,000,000 = 260,000,000. Profit is -40,000,000, which is -20 per member.
Complexity
Time O(1) and space O(1), since only a fixed number of arithmetic operations is performed.
Reference solution
from typing import Dict
def yearly_program_summary(members: int, yearly_fee: float, monthly_spend: float, commission_rate: float, fixed_cost: float, variable_cost_per_member: float, months: int) -> Dict[str, float]:
revenue_per_member = yearly_fee + monthly_spend * commission_rate * months
annual_revenue = members * revenue_per_member
annual_cost = fixed_cost + members * variable_cost_per_member
annual_profit = annual_revenue - annual_cost
profit_per_customer = annual_profit / members if members else 0.0
return {
"annual_revenue": annual_revenue,
"annual_cost": annual_cost,
"annual_profit": annual_profit,
"profit_per_customer": profit_per_customer,
}