Skip to content

Commit bf1034a

Browse files
committed
started session08 solutions, etc.
1 parent 28c6579 commit bf1034a

File tree

3 files changed

+765
-653
lines changed

3 files changed

+765
-653
lines changed

Solutions/Session07/circle.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
"""
66

77
from math import pi
8+
import functools
89

910

11+
@functools.total_ordering
1012
class Circle(object):
1113

1214
def __init__(self, radius):
@@ -56,8 +58,33 @@ def __imul__(self, factor):
5658
def __rmul__(self, factor):
5759
return Circle(self.radius * factor)
5860

59-
def __cmp__(self, other):
60-
return cmp(self.radius, other.radius)
61+
# def __cmp__(self, other):
62+
# """
63+
# This is the easy way to support comparing all in one shot
64+
# """
65+
# return cmp(self.radius, other.radius)
66+
67+
## Or you can define them all
68+
## So can support odd situations
69+
# def __eq__(self, other):
70+
# return self.radius == other.radius
71+
# def __ne__(self, other):
72+
# return self.radius != other.radius
73+
# def __gt__(self, other):
74+
# return self.radius > other.radius
75+
# def __ge__(self, other):
76+
# return self.radius >= other.radius
77+
# def __lt__(self, other):
78+
# return self.radius < other.radius
79+
# def __le__(self, other):
80+
# return self.radius <= other.radius
81+
82+
## or you can put the @total_ordering decorator on the class definiton and do this:
83+
def __eq__(self, other):
84+
return self.radius == other.radius
85+
def __gt__(self, other):
86+
return self.radius > other.radius
87+
6188

6289

6390
class SubCircle(Circle):

0 commit comments

Comments
 (0)