Advertisement
here2share

# regular_playing_cards.py

Jan 6th, 2015
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # regular_playing_cards.py
  2.  
  3. import random
  4.  
  5. class Card(object):
  6.     suits = ("Clubs","Hearts","Spades","Diamonds")
  7.     pips = ("2","3","4","5","6","7","8","9","10","Jack","Queen","King","Ace")
  8.  
  9.     def __init__(self, pip,suit):
  10.         self.pip=pip
  11.         self.suit=suit
  12.  
  13.     def __str__(self):
  14.         return "%s %s"%(self.pip,self.suit)
  15.  
  16. class Deck(object):
  17.     def __init__(self):
  18.         self.deck = [Card(pip,suit) for suit in Card.suits for pip in Card.pips]
  19.  
  20.     def __str__(self):
  21.         return "[%s]"%", ".join( (str(card) for card in self.deck))
  22.  
  23.     def shuffle(self):
  24.         random.shuffle(self.deck)
  25.  
  26.     def deal(self):
  27.         self.shuffle()  # Can't tell what is next from self.deck
  28.         return self.deck.pop(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement