Recovering the initial context

A repair invoice contains a fixed service charge plus parts costing 11, 8, and 17 dollars. There are no taxes, discounts, or other charges. The following helper adds the parts costs to an initial accumulator containing the service charge.


Python
def invoice(costs, i, total):
    if i == len(costs):
        return total
    return invoice(costs, i + 1, total + costs[i])


The call invoice([11, 8, 17], 0, service_charge) returns 64 dollars. What initial service charge was passed? Answer in dollars, to zero decimal places.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Context-Preserving Accumulators Questions: