File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Writing Functions in Python Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 6868"""!!!
6969co-worker forgot to write a docstring for log_product(),
7070To 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+ **********************************************************************************************************************************************************"""
You can’t perform that action at this time.
0 commit comments