forked from gregoriorobles/ptavi-p2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calcplus.py
56 lines (44 loc) · 1.63 KB
/
calcplus.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
50
51
52
53
54
55
56
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 28 12:36:31 2018
@author: victor
"""
import sys
from calcoohija import CalculadoraHija
if __name__ == "__main__":
mi_calcu = CalculadoraHija()
fich = open(sys.argv[1], "r")
lista = fich.readlines()
fich.close()
for line in lista:
listasin = line.split(",")
listasin[-1] = listasin[-1][:-1]
operacion = listasin[0]
operandos = listasin[1:]
print(operandos)
if operacion == "suma":
op_aux = int(operandos[0])
for operando in operandos[1:]:
op_aux = mi_calcu.plus(op_aux, int(operando))
print("El resultado de la suma es:", op_aux)
elif operacion == "resta":
op_aux = int(operandos[0])
for operando in operandos[1:]:
op_aux = mi_calcu.minus(op_aux, int(operando))
print("El resultado de la resta es:", op_aux)
elif operacion == "multiplica":
op_aux = int(operandos[0])
for operando in operandos[1:]:
op_aux = mi_calcu.multi(op_aux, int(operando))
print("El resultado de la multiplicacion es:", op_aux)
elif operacion == "divide":
op_aux = int(operandos[0])
try:
for operando in operandos[1:]:
op_aux = mi_calcu.division(op_aux, int(operando))
print("El resultado de la division es:", op_aux)
except ZeroDivisionError:
sys.exit("Error: Division by zero is not allowed")
else:
print("Operacion no valida")