Skip to content
Snippets Groups Projects
Commit 24c713fb authored by Belfadel Mohamed's avatar Belfadel Mohamed
Browse files

repr

parent b88fe4de
No related branches found
No related tags found
No related merge requests found
TP9/card.py 100644 → 100755
...@@ -53,7 +53,8 @@ class Card(object): ...@@ -53,7 +53,8 @@ class Card(object):
précondition : value in VALUES and color in COLORS précondition : value in VALUES and color in COLORS
""" """
... self.value = value
self.color = color
def __hash__(self) -> int: def __hash__(self) -> int:
...@@ -66,11 +67,11 @@ class Card(object): ...@@ -66,11 +67,11 @@ class Card(object):
""" """
return a string representation of the card return a string representation of the card
$$$ Card('Ace', 'heart') $$$ repr(Card('Ace', 'heart'))
Card("Ace", "heart") 'Card("Ace", "heart")'
""" """
... return f"Card(\"{self.value}\", \"{self.color}\")"
def compare(self, card: Card) -> int: def compare(self, card: Card) -> int:
""" """
compares cards. compares cards.
...@@ -97,7 +98,14 @@ class Card(object): ...@@ -97,7 +98,14 @@ class Card(object):
$$$ c1.compare(c3) == 0 $$$ c1.compare(c3) == 0
True 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 @staticmethod
def deck(n_card: int) -> list[Card]: def deck(n_card: int) -> list[Card]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment