From 24c713fb40036d3413a7aff9d21ffe77e577ea93 Mon Sep 17 00:00:00 2001 From: Belfadel Mohamed <mohamed.belfadel.etu@118p2.fil.univ-lille.fr> Date: Wed, 27 Mar 2024 09:30:39 +0100 Subject: [PATCH] repr --- TP9/card.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) mode change 100644 => 100755 TP9/card.py diff --git a/TP9/card.py b/TP9/card.py old mode 100644 new mode 100755 index 4844315..8732779 --- 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]: -- GitLab