Skip to content

Instantly share code, notes, and snippets.

@stefanpejcic
Created September 25, 2019 08:52
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 stefanpejcic/ba1077f69bbb806d3fcbe4fcb75aa7fe to your computer and use it in GitHub Desktop.
Save stefanpejcic/ba1077f69bbb806d3fcbe4fcb75aa7fe to your computer and use it in GitHub Desktop.
Simple calculator with the operator instead of if
import operator
ops = {
"+": operator.add,
"-": operator.sub,
"/": operator.truediv,
"*": operator.mul,
"**": pow
}
print(ops['-'](50, 25))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment