diff options
author | Cristian García <cristian99garcia@gmail.com> | 2013-08-28 22:20:04 (GMT) |
---|---|---|
committer | Cristian García <cristian99garcia@gmail.com> | 2013-08-28 22:20:04 (GMT) |
commit | 09d2d5f80f54f6fc6386cf12cc90d805226cafd5 (patch) | |
tree | 17787648a47458dbfc59c14859c6d23b424580ce | |
parent | 2cfad03da1d8201b96d6c4742aabfc12d563bea6 (diff) |
Ahora busca los semejantes correctamente
-rw-r--r-- | Calculadora.py | 75 |
1 files changed, 57 insertions, 18 deletions
diff --git a/Calculadora.py b/Calculadora.py index a232cd1..d1d2003 100644 --- a/Calculadora.py +++ b/Calculadora.py @@ -14,10 +14,10 @@ class Calculadora(): else: if '=' in operacion: - self.resolver_ecuacion(operacion) + self.buscar_semejantes(operacion) else: - self.resolver_polinomio(operacion) + self.buscar_semejantes(operacion) def operar(self, operacion): @@ -35,7 +35,7 @@ class Calculadora(): pass - def resolver_polinomio(self, operacion): + def buscar_semejantes(self, operacion): def agregar_operacion(lista, operacion): @@ -50,6 +50,15 @@ class Calculadora(): if '*' in operacion: lista = operacion.split('*') + elif not '*' in operacion and '/' in operacion: + lista = operacion.split('/') + + elif not '/' in operacion and '+' in operacion: + lista = operacion.split('+') + + elif not '+' in operacion and '-' in operacion: + lista = operacion.split('-') + for x in range(0, len(lista)*2, 2): lista.insert(x, '*') @@ -60,26 +69,56 @@ class Calculadora(): for x2 in x.split('/'): lista.insert(numero + x.split('/').index(x2), x2) + for x in lista: + if '+' in x: + numero = lista.index(x) + lista.remove(x) + for x2 in x.split('+'): + lista.insert(numero + x.split('+').index(x2), x2) + + for x in lista: + if '-' in x: + numero = lista.index(x) + lista.remove(x) + for x2 in x.split('-'): + lista.insert(numero + x.split('-').index(x2), x2) + agregar_operacion(lista, '/') - semejantes = [] + semejantes = {} + lista = self.limpiar_valor(lista) for x in lista: - if x and x[-1] == 'x': - lista1 = [x] - try: - if lista[lista.index(x)+1] != x: - lista1.append(lista[lista.index(x)+1]) - - except: - pass - - semejantes.append(lista1) - #for x in semejantes: - # self.limpiar_valor(x) - - print lista, semejantes + if x and x[-1] == 'x' and not 'e' in x: + if not semejantes.get(1): + semejantes[1] = [] + + semejantes[1].append(x) + + elif x and 'x' in x and 'e' in x: + numero = -1 + l = [] + s = '' + while True: + v = (x[numero]) + if v == 'e': + break + + else: + l.append(v) + + numero -= 1 + + for x2 in l[::-1]: + s += x2 + + if not semejantes.get(int(s)): + semejantes[int(s)] = [] + + semejantes[int(s)].append(x) + + print semejantes def limpiar_valor(self, valor): |