Last active
April 3, 2024 01:37
-
-
Save mcsee/c805ea4caee48b9ce7b37c2dcec0a594 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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