forked from gregoriorobles/ptavi-p2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calcoo.py
35 lines (24 loc) · 888 Bytes
/
calcoo.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
import sys
class Calculadora(object):
def __init__(self, operando1, operando2, operador):
self.operando1 = operando1
self.operando2 = operando2
self.operador = operador
def suma(self):
return self.operando1 + self.operando2
def resta(self):
return self.operando1 - self.operando2
if __name__ == "__main__":
while len(sys.argv) != 4:
sys.exit("Input: python3 calc.py operando1 operador operando2")
try:
Usarcalc = Calculadora(float(sys.argv[1]), float(sys.argv[3]),
sys.argv[2])
except ValueError:
sys.exit("Los operandos tienen que ser números")
if Usarcalc.operador == "suma":
print(Usarcalc.suma())
elif Usarcalc.operador == "resta":
print(Usarcalc.resta())
else:
sys.exit('Operación sólo puede ser sumar o restar.')