Track a modified input and separate returned data

An engineer stores temperature readings in degrees Celsius and uses this Python function to add a reading and calculate deviations from the updated mean:


Python
def record_and_center(readings, new_value):
    readings.append(new_value)
    mean = sum(readings) / len(readings)
    centered = [value - mean for value in readings]
    return mean, centered

samples = [18.0, 22.0]
average, deviations = record_and_center(samples, 24.5)
deviations[0] = -2.0


After every statement has executed, report average, samples[0], len(samples), and deviations[2]. Give the average, first sample, and last deviation in degrees Celsius to one decimal place. Give the number of samples as an exact integer. Python list indices start at zero.

Your answers

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 User-Defined Functions Questions: