Skip to content

Instantly share code, notes, and snippets.

@oten oten/calc3.py
Created Oct 7, 2015

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.