Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Card:
- suits = ['Clubs', 'Diamonds', 'Hearts', 'Spades']
- ranks = [None, 'Ace', '2', '3', '4', '5',
- '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']
- def __init__(self, suit, rank):
- self.suit=suit
- self.rank=rank
- def __str__(self):
- return '%s %s' % (self.suits[self.suit], self.ranks[self.rank])
- class Deck:
- def __init__(self):
- self.cards=[]
- for suit in range (4):
- for rank in range(1, 14):
- card=Card(suit, rank)
- self.cards.append(card)
- def __str__(self):
- res = [str(card) for card in self.cards]
- return '\n'.join(res)
- def shuffle(self):
- import random
- random.shuffle(self.cards)
- def pop_card(self):
- return self.cards.pop()
- def add_card(self, card):
- self.cards.append(card)
- def move_cards(self, hand, num):
- for i in range(num):
- hand.add_card(self.pop_card())
- class Hand(Deck):
- def __init__(self, label=''):
- self.cards=[]
- self.label=label
- hand1=Hand('player1')
- deck = Deck()
- deck.shuffle()
- deck.move_cards(hand1, 5)
- for item in hand1.cards:
- print item
- ranks = [i.split()[1] for i in hand1.cards]
Advertisement
Add Comment
Please, Sign In to add comment