diff --git a/TP9/card.py b/TP9/card.py old mode 100644 new mode 100755 index 484431545f8ac56c86296bf88f1faab9424b41b8..87327796900d438f6d6b9b255604987d70f43a0d --- a/TP9/card.py +++ b/TP9/card.py @@ -53,7 +53,8 @@ class Card(object): précondition : value in VALUES and color in COLORS """ - ... + self.value = value + self.color = color def __hash__(self) -> int: @@ -66,11 +67,11 @@ class Card(object): """ return a string representation of the card - $$$ Card('Ace', 'heart') - Card("Ace", "heart") + $$$ repr(Card('Ace', 'heart')) + 'Card("Ace", "heart")' """ - ... - + return f"Card(\"{self.value}\", \"{self.color}\")" + def compare(self, card: Card) -> int: """ compares cards. @@ -97,7 +98,14 @@ class Card(object): $$$ c1.compare(c3) == 0 True """ - ... + + if Card.VALUES.index(self.value) > Card.VALUES.index(card.value): + res = 1 + elif Card.VALUES.index(self.value) < Card.VALUES.index(card.value): + res = -1 + else: + res = 0 + return res @staticmethod def deck(n_card: int) -> list[Card]: