Skip to content

Instantly share code, notes, and snippets.

@oten
Created October 7, 2015 15:27
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 oten/057d50bfa1026ddb9a2b to your computer and use it in GitHub Desktop.
Save oten/057d50bfa1026ddb9a2b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
def sw(op):
return [lambda a, b: a + b,
lambda a, b: a - b,
lambda a, b: a * b,
lambda a, b: a / b,
lambda a, b: "err: operação inválida!"]['+-*/'.find(op)]
from sys import argv
if len(argv) != 4:
print(
"""Usage:
{0} num_1 op num_2
Ex.:
{0} 2 + 2
4.0""".format(argv[0]))
exit(-1)
num_1, op, num_2 = argv[1:]
num_1 = float(num_1)
num_2 = float(num_2)
print(sw(op)(num_1, num_2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment