Skip to content

Instantly share code, notes, and snippets.

@Phyks
Last active August 29, 2015 14:01
Show Gist options
  • Save Phyks/a30f4c3333303d97994c to your computer and use it in GitHub Desktop.
Save Phyks/a30f4c3333303d97994c to your computer and use it in GitHub Desktop.
def function_toute_prete(y):
return y
def operation(n):
"""
operation(n) is a function that adds n to its argument if n = 0 [2] or multiply n by its two arguments if n = 1 [2].
For instance, add(3) : x -> x * 3
"""
functions = [
lambda x: n + x,
lambda x,y : n * x * y,
lambda x: n * x,
lambda x: n / x,
lambda y: function_toute_prete(y)
]
if n < len(functions) - 1:
return functions[n]
else:
return None
mul3 = operation(3)
print(mul3(3,2)) # Prints 18
add6 = operation(6)
print(add6(4)) # Prints 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment