Separate stored defaults from current settings

A sensor program stores raw readings and its baseline in millivolts. Its gain is dimensionless. The following Python code runs at module level, creating two anonymous functions before updating the settings:


Python
gain = 2
baseline = 5
live = lambda raw: gain * (raw - baseline)
held = lambda raw, gain=gain: gain * (raw - baseline)

gain = 4
baseline = 7
live_result = live(12)
held_result = held(12)


Find live_result and held_result. Enter each result in mV, to the nearest integer.

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 Lambda Abstraction Questions: