Last active
August 29, 2015 14:01
-
-
Save Phyks/a30f4c3333303d97994c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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