PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def factorial(n):
if n ==1:
return 1
else:
return n*factorial(n-1)
def decor(func, color="Black"):
def wrap(x):
print(x,"-----",color)
return func(x)
return wrap
print("The problem 1. You can't use\n unother name of decorated\n function, because recursion:")
decorated = decor(factorial)
print ("!=",decorated(3))
print ("\nThe problem 2. I can't find the\n way to change the parameter of decoration.\n ...")
undecorated = factorial
factorial = decor(factorial, color = "Red")
print ("!=",factorial(3))
factorial = decor(factorial, color ='Green')
print ("!=",factorial(4))
print("\nMy solution is simple, you just need to save the undecorated function")
factorial = undecorated
factorial = decor(factorial, color = "Blue")
print ("!=",factorial(3))
factorial = undecorated
factorial = decor(factorial, color ='Yellow')
print ("!=",factorial(4))
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run