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

Primera version

parent 0414acf2
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import sys
def plus(op1, op2):
""" Function to sum the operands """
def to_number(num):
if '.' in num:
return float(num)
return int(num)
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__":
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))
sys.exit('Operación sólo puede ser sumar o restar.')
print ("Not allowed operation ", operation)
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