Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raganmd/bedfd1126a2b3e58233391dfd93a688f to your computer and use it in GitHub Desktop.
Save raganmd/bedfd1126a2b3e58233391dfd93a688f to your computer and use it in GitHub Desktop.
def switcher(func_name, val1, val2):
functions = {
"Add" : Add,
"Subtract" : Subtract,
"Multiply" : Multiply,
"Divide" : Divide
}
active_function = functions.get(func_name)
result = active_function(val1, val2)
return result
def Add(val1, val2):
sum_val = val1 + val2
return sum_val
def Subtract(val1, val2):
sum_val = val1 - val2
return sum_val
def Multiply(val1, val2):
sum_val = val1 * val2
return sum_val
def Divide(val1, val2):
sum_val = val1 / val2
return sum_val
print( switcher("Subtract", 1, 2) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment