Pass a calculation rule into a function

A numerical comparison tool uses the following Python functions. All inputs and outputs in this example are dimensionless.


Python
def shifted_square(x):
    return (x - 1.0) ** 2

def doubled(x):
    return 2.0 * x

def output_change(model, x0, x1):
    return model(x1) - model(x0)


Each table row represents a call to output_change with the listed function and numerical arguments. Complete the returned changes as exact integers. A function name without parentheses passes the function itself as an argument.

Function argumentx0x1Returned change
shifted_square14
doubled14
shifted_square42

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: