Question: language python # 11.4 A representation of a common-- though far from the only-- ranking of cards in card decks. # For simplicity, the design




language python
# 11.4 A representation of a common-- though far from the only-- ranking of cards in card decks. # For simplicity, the design assumes that the ranking is uniform by suit - # an assumption that fails to hold for (e.g.) euchre-family card games. class Cardvalues(object): def __init__(self, values = ['ace', 'king', 'queen', 'jack', '10', '9', 'S', '7', '6', '5', '4', '3', '2']): self.vals = values def __len_(self): return len(self.vals) def __getitem__(self, i): return self.vals[1] def _eq__(self, other): return isinstance(other, cardvalues) and len(self) -- len(other) and all([self[i] == other[i] for i in range(e, len(self def values(self): return self.vals def outranks(self, v1, v2): assert vi in self.vals, f'value (v1}) not in values ({self.vals}) assert v2 in self.vals, f'value (v2}) not in values ({self.vals})' return self.vals.index(v1) cz else ( 'outranked by' if c1 Exercise: (2 points) In the following code cell, modify the previous example so that ranking is determined by card within suit: i.e., so that all spades outrank all clubs. Provide examples that show your change was correct. # 11.4 A representation of a common-- though far from the only-- ranking of cards in card decks. # For simplicity, the design assumes that the ranking is uniform by suit - # an assumption that fails to hold for (e.g.) euchre-family card games. class Cardvalues(object): def __init__(self, values = ['ace', 'king', 'queen', 'jack', '10', '9', 'S', '7', '6', '5', '4', '3', '2']): self.vals = values def __len_(self): return len(self.vals) def __getitem__(self, i): return self.vals[1] def _eq__(self, other): return isinstance(other, cardvalues) and len(self) -- len(other) and all([self[i] == other[i] for i in range(e, len(self def values(self): return self.vals def outranks(self, v1, v2): assert vi in self.vals, f'value (v1}) not in values ({self.vals}) assert v2 in self.vals, f'value (v2}) not in values ({self.vals})' return self.vals.index(v1) cz else ( 'outranked by' if c1 Exercise: (2 points) In the following code cell, modify the previous example so that ranking is determined by card within suit: i.e., so that all spades outrank all clubs. Provide examples that show your change was correct
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
