KatInterview

Yearly Earnings Report for a Rewards Membership Program

Math & Bit ManipulationAuto-graded · 13 test cases
EasyAuto-gradedMath & Bit Manipulationmatharithmeticunit-conversion

Last 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:

  1. members (int): the number of members in the program.
  2. yearly_fee (float): the membership fee each member pays per year, in dollars.
  3. monthly_spend (float): the average amount each member spends per month, in dollars.
  4. commission_rate (float): the fraction of spending the program earns as commission, given as a decimal (for example, 0.01 means 1%).
  5. fixed_cost (float): the fixed cost of running the program per year, in dollars. It does not depend on the number of members.
  6. variable_cost_per_member (float): the cost per member per year, in dollars.
  7. 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_cost plus variable_cost_per_member multiplied by members.
  • 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. If members is 0, profit per member is 0.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.0 when there are no members).

Constraints

  • members is a non-negative integer.
  • All monetary inputs are non-negative numbers.
  • commission_rate is a decimal fraction, not a percentage.
  • months is 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.