"""card: suit, value deck: 52 card instances (sequence) shuffle cut deal""" class Card: def __init__ (self, suit, value): self.suit = suit self.value = value def __str__ (self): return str(self.value) + " of " + self.suit + "s" def __int__(self): if self.value == "Jack": return 11 if self.value == "Queen": return 12 if self.value == "King": return 13 if self.value == "Ace": return 14 return self.value def __gt__(self, othercard): return int(self) > int(othercard) def __eq__(self, othercard): return int(self) == int(othercard) def __lt__(self, othercard): return int(self) < int(othercard) def __le__(self, othercard): return int(self) <= int(othercard) def __add__(self, other): return int(self) + int(other) import random class Deck: def __init__(self): self.cards = [] for suit in ["Spade","Heart","Club","Diamond"]: for val in range(2, 11)+["Jack","Queen","King","Ace"]: newcard = Card(suit, val) # self.cards += [newcard] self.cards.append(newcard) def __str__(self): ans = "" for card in self.cards: ans += str(card) + ", " return ans def shuffle(self): random.shuffle(self.cards) def cut(self): depth = random.randint(0,52) top = self.cards[:depth] bottom = self.cards[depth:] self.cards = bottom + top def deal(self): return self.cards.pop(0) class Hand: def __init__(self): self.cards = [] def __str__(self): ans = "" for card in self.cards: ans += str(card) + ", " return ans def take(self, oneCard): self.cards += [oneCard] def discard(self): return self.cards.pop(0) def pickup(self, pile): self.cards += pile.cards pile.cards = [] def count(self): return len(self.cards) def total(self): sum = 0 for card in self.cards: sum += int(card) return sum