Skip to content

Instantly share code, notes, and snippets.

@agusrichard
Created January 23, 2021 15:23
Show Gist options
  • Save agusrichard/b7bda4dbcd48fbfbd0ef5db58e113db0 to your computer and use it in GitHub Desktop.
Save agusrichard/b7bda4dbcd48fbfbd0ef5db58e113db0 to your computer and use it in GitHub Desktop.
# Simple calculator function with limited funcionalities
def simple_calculator(operation):
"""Returns operation we want, either add, subtract, multiply or divide"""
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
if operation == "add":
return add
elif operation == "subtract":
return subtract
elif operation == "multiply":
return multiply
elif operation == "divide":
return divide
else:
raise Exception("Must be either add, subtract, multiply, or divide")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment