Commit cda66ec9 authored by ronny javier soria erazo's avatar ronny javier soria erazo
Browse files

Primera version

parent 0414acf2
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
def plus(op1, op2):
""" Function to sum the operands """
def to_number(num):
try:
if '.' in num:
return float(num)
else:
return int(num)
except:
sys.exit("Error")
def sum(op1, op2):
return op1 + op2
def minus(op1, op2):
""" Function to substract the operands """
def substraction(op1, op2):
return op1 - op2
if __name__ == "__main__":
try:
operando1 = int(sys.argv[1])
operando2 = int(sys.argv[3])
except ValueError:
sys.exit("Error: Non numerical parameters")
if sys.argv[2] == "suma":
result = plus(operando1, operando2)
elif sys.argv[2] == "resta":
result = minus(operando1, operando2)
def do_operation(operation, op1, op2):
if operation == "suma":
print(sum(op1, op2))
elif operation == "resta":
print(substraction(op1, op2))
else:
sys.exit('Operación sólo puede ser sumar o restar.')
print ("Not allowed operation ", operation)
print(result)
if __name__ == "__main__":
op1 = to_number(sys.argv[1])
operation = sys.argv[2]
op2 = to_number(sys.argv[3])
do_operation(operation, op1, op2)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment