CodingNeed.

3 · Work with collections · 8 MIN

Reuse a function

Functions turn inputs into outputs.

def defines a reusable function. Parameters receive arguments. return exits the function with a value. A function that reaches the end without return gives None.

A small machine takes an ingredient, performs one operation, and gives you a result.

Read the example

def double(n):
    return n * 2

print(double(4))
Check the expected output
8

Your challenge

Return the larger of input["a"] and input["b"]. Equal values should return that value.

Common trap

print displays a value but does not return it from your function.

Next lesson: Keep an ordered list