-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalcplus.py
37 lines (30 loc) · 864 Bytes
/
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 28 18:03:42 2019
@author: ana
"""
import sys
import calcoohija
if __name__ == "__main__":
if len(sys.argv) != 2:
sys.exit("Usage: calcplus.py fichero")
_, input = sys.argv
fichero = open(input, 'r')
datos = fichero.readlines()
for linea in datos:
s = linea.split(',')
try:
operacion, op1 = s[0], float(s[1])
except ValueError:
print("Valor introducido no valido")
continue
for op2 in s[2:]:
try:
calcu = calcoohija.CalculadoraHija(op1, operacion, float(op2))
resultado = calcu.operar()
op1 = resultado
except ValueError:
print("Valor introducido no valido")
print(resultado)
fichero.close()