from dataclasses import dataclass from enum import Enum from typing import Optional class Value(Enum): Two = 1 Three = 2 Four = 3 Five = 4 Six = 5 Seven = 6 Eight = 7 Nine = 8 Ten = 9 Jack = 10 Queen = 11 King = 12 Ace = 13 class Color(Enum): Hearts = "♥" Spades = "♠" Clubs = "♣" Diamonds = "♦" @dataclass(frozen=True) class Card: value: Value color: Optional[Color] = None def __cmp__(self, other: "Card"): my = self.score() their = other.score() return (my > their) - (my < their) def __lt__(self, other: "Card"): return self.score() < other.score() def __gt__(self, other: "Card"): return self.score() > other.score() def __eq__(self, other: "Card"): return self.score() == other.score() def __str__(self) -> str: return f"{self.value.name} of {self.color.value if self.color else '?'}" def score(self) -> int: return int(self.value.value) def lowest_value_and_rest(): lowValue: Value = Value.Two otherValues = list(Value) otherValues.remove(lowValue) return lowValue, otherValues