Tracing a calculation that remembers earlier calls

A sensor-checking function should return the mean signed pressure error for the readings supplied in its current call. Each error is a reading minus the reference pressure, and all pressures are in kPa.


The following Python code executes once. The three calls then run in the order shown, without restarting the program or clearing the list.


Python
errors = []

def mean_error(readings, reference):
    for reading in readings:
        errors.append(reading - reference)
    return sum(errors) / len(errors)

first = mean_error([102, 104], 100)
second = mean_error([98, 100], 100)
third = mean_error([106], 100)


Complete the table with the number of errors stored immediately after each call, the mean actually returned, and the mean required by the specification. Enter exact integers; the two mean columns are in kPa.

CallStored error countReturned mean (kPa)Required mean (kPa)
First
Second
Third

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 Software Debugging Questions: