Skip to content

Instantly share code, notes, and snippets.

@oten
Created October 7, 2015 15:26
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/93614bdb539a0f152731 to your computer and use it in GitHub Desktop.
Save oten/93614bdb539a0f152731 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
sw = {'+': lambda a, b: a + b,
'-': lambda a, b: a - b,
'*': lambda a, b: a * b,
'/': lambda a, b: a / b}
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