Lecture Notes on 31 Jan 2014 import random class Card (object): RANKS = (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) SUITS = ('C', 'D', 'H', 'S') def __init__ (self, rank = 12, suit = 'S'): if (rank in Card.RANKS): self.rank = rank else: self.rank = 12 if (suit in Card.SUITS): self.suit = suit else: self.suit = 'S' def __str__ (self): if self.rank == 14: rank = 'A' elif self.rank == 13: rank = 'K' elif self.rank == 12: rank = 'Q' elif self.rank == 11: rank = 'J' else: rank = self.rank return str(rank) + self.suit def __eq__ (self, other): return (self.rank == other.rank) def __ne__ (self, other): return (self.rank != other.rank) def __lt__ (self, other): return (self.rank < other.rank) def __le__ (self, other): return (self.rank <= other.rank) def __gt__ (self, other): return (self.rank > other.rank) def __ge__ (self, other): return (self.rank >= other.rank) class Deck (object): def __init__ (self): self.deck = [] for suit in Card.SUITS: for rank in Card.RANKS: card = Card (rank, suit) self.deck.append (card) def shuffle (self): random.shuffle (self.deck) def deal (self): if len(self.deck) == 0: return None else: return self.deck.pop(0) class Poker (object): def __init__ (self, numHands): self.deck = Deck() self.deck.shuffle() self.hands = [] numCards_in_Hand = 5 for i in range (numHands): hand = [] for j in range (numCards_in_Hand): hand.append (self.deck.deal()) self.hands.append (hand) def play (self): for i in range (len(self.hands)): sortedHand = sorted (self.hands[i], reverse = True) hand = '' for card in sortedHand: hand = hand + str(card) + ' ' print ('Hand ' + str(i + 1) + ': ' + hand) ''' def is_royal (self, hand): ... def is_straight_flush (self, hand): ... def is_four (self, hand): ... def is_full (self, hand): ... def is_flush (self, hand): ... def is_straight (self, hand): ... def is_three (self, hand): ... def is_two (self, hand): ... def is_one (self, hand): ... def is_high (self, hand): ... ''' def main(): numHands = int (input ('Enter number of hands to play: ')) while (numHands < 2 or numHands > 6): numHands = int (input ('Enter number of hands to play: ')) game = Poker (numHands) game.play() main()