Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- import random
- class Deck(object):
- def __init__(self,max_cards):
- self.suit_list = ['heart','diamond','club','spade']
- self.cards_held = []
- self.max = max_cards
- # if 52 create a new deck
- if self.max == 52:
- for card_num in range(0,52):
- face = str(card_num % 13)
- if face == '0':
- face = 'K'
- if face == '1':
- face = 'A'
- if face == '12':
- face = 'Q'
- if face == '11':
- face = 'J'
- suit_index = (card_num/13) % 13
- suit = self.suit_list[suit_index]
- self.cards_held.append((face,suit))
- def draw(self):
- next = self.cards_held.pop(random.randint(0,len(self.cards_held)-1))
- return next
- def pickup(self,new_card):
- if len(self.cards_held) <= self.max:
- self.cards_held.append(new_card)
- return 0
- else:
- return -1
- my_deck = Deck(52)
- print(my_deck.suit_list)
- print(my_deck.max)
- print(my_deck.cards_held)
- first_hand = Deck(5)
- second_hand = Deck(5)
- first_hand.pickup(my_deck.draw())
- print(first_hand.cards_held)
- sys.exit(0)
Add Comment
Please, Sign In to add comment