Skip to content

Instantly share code, notes, and snippets.

@lvreynoso
Created April 17, 2019 18:11
Show Gist options
  • Save lvreynoso/5bd2f1d5b75a2ee98fbcd20f69811beb to your computer and use it in GitHub Desktop.
Save lvreynoso/5bd2f1d5b75a2ee98fbcd20f69811beb to your computer and use it in GitHub Desktop.
High level plan: Change the calculator to a general purpose calculator that splits up input and uses python's builtin math tools.
Take in input
Split input on spaces
Cast first and last parts as Ints
If that doesn't work, return an error
Check for the operator in the middle piece of the input
If it's plus:
Add the first and last parts and return the answer.
If it's minus:
Subtract the first and last parts and return the answer.
If it's a "x":
Multiply the first and last parts and return the answer.
If it's a "/":
Divide the first part by the last part and return the answer.
If it's anything else,
Return an error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment