Skip to content

Commit e723c40

Browse files
authored
Update III Decorators.py
1 parent 8e33f23 commit e723c40

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Writing Functions in Python/III Decorators.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,32 @@
6868
"""!!!
6969
co-worker forgot to write a docstring for log_product(),
7070
To pass a function as an argument to another function, you had to determine which one you were calling and which one you were referencing."""
71+
#`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
72+
## Returning functions for a math game
73+
74+
def create_math_function(func_name):
75+
if func_name == 'add':
76+
def add(a, b):
77+
return a + b
78+
return add
79+
elif func_name == 'subtract':
80+
# Define the subtract() function
81+
def subtract(a,b):
82+
return a - b
83+
return subtract
84+
else:
85+
print("I don't know that one")
86+
87+
add = create_math_function('add')
88+
print('5 + 2 = {}'.format(add(5, 2)))
89+
90+
subtract = create_math_function('subtract')
91+
print('5 - 2 = {}'.format(subtract(5, 2)))
92+
"""!!!
93+
Since create_math_function() returns a function, we can then call those variables as functions."""
94+
95+
"""**********************************************************************************************************************************************************
96+
Scope
97+
======
98+
99+
**********************************************************************************************************************************************************"""

0 commit comments

Comments
 (0)