forked from gregoriorobles/ptavi-p2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.py
executable file
·49 lines (35 loc) · 1.06 KB
/
calc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
def plus(op1, op2):
""" Function to sum the operands """
return op1 + op2
def minus(op1, op2):
""" Function to substract the operands """
return op1 - op2
def multi(op1, op2):
"""funcion de multiplicacion"""
return op1 * op2
def divi(op1, op2):
"""funcion de dividir"""
if operando1 == 0 or operando2 == 0:
return " No se puede dividir con ceros"
else:
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)
elif sys.argv[2] == "multiplicar":
result = multi(operando1, operando2)
elif sys.argv[2] == "dividir":
result = divi(operando1, operando2)
else:
sys.exit('Operación sólo puede ser sumar o restar.')
print(result)