From decffa6d7588f52dfd5871540ceba5675d53c0b7 Mon Sep 17 00:00:00 2001 From: Lafrite Date: Wed, 30 Oct 2013 19:34:39 +0100 Subject: [PATCH] Solve the issue with self missplacement --- calculus.py | 1 - fraction.py | 16 +++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/calculus.py b/calculus.py index 62e890f..19d2fcc 100644 --- a/calculus.py +++ b/calculus.py @@ -346,7 +346,6 @@ def test(exp): #print("Bis") steps = [postfix] steps += computePostfixBis(postfix) - print(steps) print_steps(steps) #print(postfixToInfix(postfix)) #print(get_main_op(exp)) diff --git a/fraction.py b/fraction.py index c05b457..02a7dba 100644 --- a/fraction.py +++ b/fraction.py @@ -24,22 +24,20 @@ class Fraction(object): steps = [] if self._denom < 0: - self._num = - self._num - self._denom = - self._denom - steps.append(self) + n_frac = Fraction(-self._num, -self._denom) + steps.append(n_frac) gcd_ = gcd(abs(self._num), abs(self._denom)) if self._num == self._denom: - self._num = 1 - self._denom = 1 - steps.append(self) + n_frac = Fraction(1,1) + steps.append(n_frac) elif gcd_ != 1: - self._num, self._denom = self._num // gcd_ , self._denom // gcd_ - steps.append("( {reste1} * {gcd} ) / ( {reste2} * {gcd} )".format(reste1 = self._num, reste2 = self._denom, gcd = gcd_)) + n_frac = Fraction(self._num // gcd_ , self._denom // gcd_) + steps.append("( {reste1} * {gcd} ) / ( {reste2} * {gcd} )".format(reste1 = n_frac._num, reste2 = n_frac._denom, gcd = gcd_)) # Certainement le truc le plus moche que j'ai jamais fait... On ne met que des strings dans steps puis au dernier moment on met une fraction. C'est moche de ma part - steps.append(self) + steps.append(n_frac) return steps