diff options
Diffstat (limited to 'cmpsc132_homework_1-1.py')
| -rw-r--r-- | cmpsc132_homework_1-1.py | 15 |
1 files changed, 1 insertions, 14 deletions
diff --git a/cmpsc132_homework_1-1.py b/cmpsc132_homework_1-1.py index c3a1baf..77fb351 100644 --- a/cmpsc132_homework_1-1.py +++ b/cmpsc132_homework_1-1.py @@ -38,12 +38,10 @@ class Fraction: def __eq__(self, other_fraction): first_num = self.num * other_fraction.den second_num = other_fraction.num * self.den - return first_num == second_num def __add__(self, other_fraction): onum, oden = chk_frac(other_fraction) - new_num = self.num * oden \ + self.den * onum new_den = self.den * oden @@ -51,7 +49,6 @@ class Fraction: def __sub__(self, other_fraction): onum, oden = chk_frac(other_fraction) - new_num = self.num * oden \ - self.den * onum new_den = self.den * oden @@ -59,21 +56,18 @@ class Fraction: def __mul__(self, other_fraction): onum, oden = chk_frac(other_fraction) - new_num = self.num * onum new_den = self.den * oden return Fraction(new_num, new_den) def __truediv__(self, other_fraction): onum, oden = chk_frac(other_fraction) - new_num = self.num * oden new_den = self.den * onum return Fraction(new_num, new_den) def __gt__(self, other_fraction): onum, oden = chk_frac(other_fraction) - snum = self.num * oden onum = self.den * onum if snum > onum: @@ -82,7 +76,6 @@ class Fraction: def __ge__(self, other_fraction): onum, oden = chk_frac(other_fraction) - snum = self.num * oden onum = self.den * onum if snum >= onum: @@ -91,7 +84,6 @@ class Fraction: def __lt__(self, other_fraction): onum, oden = chk_frac(other_fraction) - snum = self.num * oden onum = self.den * onum if snum < onum: @@ -100,7 +92,6 @@ class Fraction: def __le__(self, other_fraction): onum, oden = chk_frac(other_fraction) - snum = self.num * oden onum = self.den * onum if snum <= onum: @@ -109,7 +100,6 @@ class Fraction: def __ne__(self, other_fraction): onum, oden = chk_frac(other_fraction) - snum = self.num * oden onum = self.den * onum if snum != onum: @@ -121,10 +111,7 @@ class Fraction: __radd__ is for when the reverse adding is needed like 1 + x instead of x + 1 """ - onum, oden = chk_frac(other_fraction) - nnum = self.num * oden + onum * self.den - nden = self.den * oden - return Fraction(nnum, nden) + return self.__add__(other_fraction) def __iadd__(self, ofrac): """ |
