@@ -40,7 +40,8 @@ def __gt__(self, other):
40
40
41
41
b > a # b.__gt__(a)
42
42
43
- b
43
+ b < a
44
+
44
45
45
46
46
47
class IntValue :
@@ -148,28 +149,38 @@ def __repr__(self):
148
149
149
150
#############################################################
150
151
151
- values = ('2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , 'J' , 'Q' , 'K' , 'A' )
152
- suits = ('clubs' , 'diamonds' , 'hearts' , 'spades' )
153
-
154
152
155
153
class Card (object ):
154
+ values = ('2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , 'J' , 'Q' , 'K' , 'A' )
155
+ suits = ('clubs' , 'diamonds' , 'hearts' , 'spades' )
156
+
156
157
def __init__ (self , value = 'A' , suit = 'spade' ):
157
158
self .value , self .suit = value , suit
158
159
print (f"In init; value is { value } ; suit is { suit } " )
159
160
160
161
def __repr__ (self ):
161
162
return "Card('%s','%s')" % (self .value , self .suit )
162
163
164
+ def __gt__ (self , other ):
165
+ if self .suits .index (self .suit ) > self .suits .index (other .suit ):
166
+ return True
167
+
168
+ if self .suits .index (self .suit ) < self .suits .index (other .suit ):
169
+ return False
170
+
171
+ return self .values .index (self .value ) > self .values .index (other .value )
172
+
163
173
164
174
165
175
krol_karo = Card ('K' , 'diamonds' )
166
176
as_karo = Card ('A' , 'diamonds' )
167
177
dycha_karo = Card ('10' , 'diamonds' )
168
178
karty_w_rece = [ as_karo , krol_karo , dycha_karo ]
169
179
170
- karty_w_rece
180
+ print ( karty_w_rece )
171
181
172
182
karty_w_rece .sort ()
183
+ print (karty_w_rece )
173
184
174
185
def moc_karty (karta ):
175
186
return len (values )* suits .index (karta .suit ) + values .index (karta .value )
0 commit comments