#| default_exp card #|export from fastcore.all import * import random #|export suits = ["♣️", "♦️", "❤️", "♠️"] ranks = [None, "A"] + [str(x) for x in range(2,11)] + ["J", "Q", "K"] #|export class Card: "Represents a standard playing card." def __init__(self, suit=0, rank=2): self.suit,self.rank = suit, rank self.suit_nm,self.rank_nm = suits[self.suit],ranks[self.rank] def __eq__(self, other): return (self.suit, self.rank) == (other.suit, other.rank) def __lt__(self, other): return (self.suit, self.rank) < (other.suit, other.rank) def __str__(self): return f'{self.rank_nm}{self.suit_nm}' __repr__ = __str__ c = Card(suit=1, rank=3) c test_eq(str(c), '3♦️') c2 = Card(suit=2, rank=11) test_eq(str(c2), 'J❤️') test_eq(c2 > c, True) #|hide assert Card(suit=1, rank=3) == Card(suit=1, rank=3) #|hide from nbdev.doclinks import nbdev_export nbdev_export()