Skip to content

Instantly share code, notes, and snippets.

Created July 12, 2017 14:58
Show Gist options
  • Save anonymous/182a9264fc8b224fde3522451396293e to your computer and use it in GitHub Desktop.
Save anonymous/182a9264fc8b224fde3522451396293e to your computer and use it in GitHub Desktop.
getopt2 created by britodfbr - https://repl.it/JYbi/7
def calc(x,y,op):
try:
x, y = int(x), int(y)
return{
'+': x + y,
'-': x - y,
'*': x * y,
'/': x // y,
'%': x % y,
}.get(op,'Error')
except:
raise
print(calc(5,2,'+'))
print(calc(5,2,'-'))
print(calc(5,2,'*'))
print(calc(5,2,'/'))
print(calc(5,2,'%'))
print(calc(5,2, 'a'))
print(calc(5,2, '**'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment