Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active April 3, 2024 01:37
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 mcsee/c805ea4caee48b9ce7b37c2dcec0a594 to your computer and use it in GitHub Desktop.
Save mcsee/c805ea4caee48b9ce7b37c2dcec0a594 to your computer and use it in GitHub Desktop.
def calculate(mathOperand, firstArgument, secondArgument):
if mathOperand == '+':
return firstArgument + secondArgument
elif mathOperand == '-':
return firstArgument - secondArgument
elif mathOperand == '*':
return firstArgument * secondArgument
elif mathOperand == '/':
if secondArgument != 0:
return firstArgument / secondArgument
else:
return "Error: Division by zero"
else:
return "Error: Invalid operation - Do not hack!"
# This is a quick solution but another smell
# You should avoid this kind of switches and iterate to
# a Polymorphic Hierarchy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment