import sys import calcoohija import csv with open(sys.argv[1]) as csvfile: operaciones = csv.reader(csvfile) for operacion in operaciones: print(operacion) try: operador = operacion[0] result = float(operacion[1]) for number in operacion[2:]: Not_Allowed = False operando = float(number) cuenta = calcoohija.CalculadoraHija(result, operando) if operador == 'suma': result = cuenta.plus() elif operador == 'resta': result = cuenta.sub() elif operador == 'multiplica': result = cuenta.mux() elif operador == 'divide': result = cuenta.div() else: Not_Allowed = True
if __name__ == "__main__": if len(sys.argv) != 2: sys.exit("Input: python3 calcplus.py fichero") with open(sys.argv[1], newline='') as f: Fich = csv.reader(f) for Linea in Fich: Operador = Linea[0] Total = Linea[1] Operandos = Linea[2:] for Operando in Operandos: try: Operar = calcoohija.CalculadoraHija( float(Total), float(Operando)) except ValueError: sys.exit("Los operandos tienen que ser números") if Operador == "suma": Total = Operar.suma() elif Operador == "resta": Total = Operar.resta() elif Operador == "multiplica": Total = Operar.multiplica() elif Operador == "divide": Total = Operar.divide() else:
#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys import csv import calcoohija if __name__ == "__main__": calculadora = calcoohija.CalculadoraHija() diccOperador = { 'suma': calculadora.plus, 'resta': calculadora.minus, 'multiplica': calculadora.multiplica, 'divide': calculadora.divide } with open(sys.argv[1]) as fichero: reader = csv.reader(fichero) for row in reader: operador = row[0] result = int(row[1]) row = row[2:] for operando in row: try: result = diccOperador[operador](result, int(operando)) except KeyError: sys.exit('Operación sólo puede ser suma, resta, multiplica' ' o divide')
#!/usr/bin/python3 import sys import calcoohija import csv entrada = sys.argv[1] with open(entrada) as fichero: for linea in fichero.readlines(): lista = linea[:-1].split(",") operacion = lista[0] operadores = lista[1:] resultado = float(operadores[0]) calcuPlus = calcoohija.CalculadoraHija() for operando in operadores[1:]: resultado = calcuPlus.operar(operacion,resultado,float(operando)) print(resultado)
#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys import calcoohija if __name__ == "__main__": try: file = open(sys.argv[1], "r") except ValueError: sys.exit("Error: The argument is not valid") for line in file.readlines(): line = line.rstrip('\n') operations = line.split(',') arg = operations[0] result = int(operations[1]) for operands in operations[2:]: calculator = calcoohija.CalculadoraHija(result, int(operands)) result = calculator.operate(arg) print(result) file.close()
#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys import calcoohija import csv with open(sys.argv[1]) as file_calc: lines = csv.reader(file_calc) for line in lines: operador = line[0] resultado = int(line[1]) for arg in line[2:]: if operador == 'suma': resultado = calcoohija.CalculadoraHija(int(arg), resultado).suma() if operador == 'resta': resultado = calcoohija.CalculadoraHija(resultado, int(arg)).resta() if operador == 'multiplica': resultado = calcoohija.CalculadoraHija(int(arg), resultado).multiplica() if operador == 'divide': resultado = calcoohija.CalculadoraHija(resultado, int(arg)).divide() print(resultado)
import sys import csv import calcoohija try: with open(sys.argv[1], ) as csvfile: # abrir fichero operacionesreader = csv.reader(csvfile) # leer fichero for operacion in operacionesreader: try: operador = operacion[0] # suma, 1, 2, 3, 4, 5 -> suma resultado = float(operacion[1]) # suma, 1, 2, 3, 4, 5 -> 1 for operando in operacion[2:]: num = float(operando) objeto = calcoohija.CalculadoraHija(resultado, num) if operador == 'suma': resultado = objeto.suma() elif operador == 'resta': resultado = objeto.resta() elif operador == 'multiplica': resultado = objeto.mult() elif operador == 'divide': resultado = objeto.div() else: sys.exit('operacion,num,num...') print(resultado) except ValueError: sys.exit('Error: debe usar numeros')
for Row in Reader: try: Count = float(Row[1]) except ValueError: sys.exit(" Non numerical parameters") # Operando no es nª for Num in Row[2:]: try: Num2 = float(Num) except ValueError: sys.exit(" Non numerical parameters") # El resto Opr = Row[0] CH = calcoohija.CalculadoraHija(Count, Num2) # Usamos la CalculadoraHija if Opr == "suma": Count = CH.suma() elif Opr == "resta": Count = CH.resta() elif Opr == "multiplica": Count = CH.mul() elif Opr == "divide": if Num2 == 0: sys.exit("Division by zero is not allowed") else: Count = CH.div() else:
#!/usr/bin/python3 # -*- coding: utf-8 -*- import calcoohija as ch if __name__ == "__main__": if (len(ch.sys.argv) == 4): try: operando1 = int(ch.sys.argv[1]) operando2 = int(ch.sys.argv[3]) except ValueError: ch.sys.exit("Error: Non numerical parameters") op = ch.CalculadoraHija() if ch.sys.argv[2] == "suma": result = op.plus(operando1, operando2) elif ch.sys.argv[2] == "resta": result = op.minus(operando1, operando2) elif ch.sys.argv[2] == "multiplica": result = op.mult(operando1, operando2) elif ch.sys.argv[2] == "divide": result = op.div(operando1, operando2) else: ch.sys.exit('Solo se puede sumar, restar, multiplicar o dividir.') print(result) else: print("Introduzca dos operandos y un operador")
import sys import csv import calcoohija if len(sys.argv) <= 2: fichero = open(sys.argv[1], 'r') for linea in fichero: type_operation = linea.split(",")[0] operandos = linea.split(",")[1:] result = int(operandos[0]) for num in operandos[1:]: calculo = int(num) cuenta = calcoohija.CalculadoraHija(result, calculo) if type_operation == "suma": result = cuenta.plus() elif type_operation == "resta": result = cuenta.minus() elif type_operation == "multiplica": result = cuenta.mult() elif type_operation == "divide": result = cuenta.div() else: sys.exit('Error. Non numerical parameters') print(result) else:
try: calculos = open(str(sys.argv[1]), "r") lineas = calculos.readlines() calculos.close() except FileNotFoundError: sys.exit("File not found!!") for operaciones in lineas: try: operaciones = operaciones[:-1].split(",") ops = operaciones[1:] indice = 0 resultado = int(ops[0]) for indice in range(len(ops) - 1): num2 = int(ops[indice + 1]) calculo = calcoohija.CalculadoraHija(resultado, num2) if operaciones[0] == "suma": resultado = calculo.plus() elif operaciones[0] == "divide": if num2 != 0: resultado = calculo.div() else: sys.exit("Division by zero is not allowed") elif operaciones[0] == "resta": resultado = calculo.minus() elif operaciones[0] == "multiplica": resultado = calculo.multi() else: sys.exit( 'Operaciones válidas: suma,resta,multiplica y divide.') except ValueError:
#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys import calcoohija fichero = open('fichero.csv', 'r') for linea in fichero.readlines(): lista = linea.split(',') operacion = lista[0] operandos = lista[1:] datos = calcoohija.CalculadoraHija() resultado = int(operandos[0]) operandos = operandos[1:] if operacion == "suma": for suma in operandos: resultado = datos.plus((resultado), int(suma)) print(resultado) elif operacion == "resta": for resta in operandos: resultado = datos.minus((resultado), int(resta))
operaciones = csv.reader(csvfile) result = 0 # Busco la operacion en la primera posicion de cada linea del fichero. for operacion in operaciones: try: operador = operacion[0] except IndexError: sys.exit("Can't read operation") # Me quedo con la parte de la lista de los operadores. operadores = operacion[1:] try: if operador == "suma": result = int(operacion[1]) for operandos in operadores[1:]: operar = calcoohija.CalculadoraHija(result, int(operandos)) result = operar.suma() print(result) elif operador == "resta": result = int(operacion[1]) for operandos in operadores[1:]: operar = calcoohija.CalculadoraHija(result, int(operandos)) result = operar.resta() print(result) elif operador == "multiplica": result = int(operacion[1]) for operandos in operadores[1:]: operar = calcoohija.CalculadoraHija(result, int(operandos)) result = operar.multiplicacion()
#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys import calcoohija if __name__ == '__main__': calcuplus = calcoohija.CalculadoraHija(operando1, operando2) fichero = open(sys.argv[1] "r") lineas = fichero.readlines() if operacion == "suma": resultado = calcuplus.suma() elif operacion == "resta": resultado = calcuplus.resta() elif operacion == "multiplica": resultado = calcuplus.multiplica() elif operacion == "divide": try: resultado = calcuplus.divide() except ZeroDivisionError: sys.exit("Division by zero is not allowed") Fichero.close()