Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- class Card:
- suit_names = ["Clubs", "Diamonds", "Hearts", "Spades"]
- rank_names = [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 (Card.rank_names[self.rank] + " " +
- Card.suit_names[self.suit])
- class DeckOfCard:
- 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):
- result = "\n"
- for card in self.cards:
- result += str(card) + "\n"
- return result
- def shuffle(self):
- random.shuffle(self.cards)
- deck = DeckOfCard()
- deck.shuffle()
- print(deck)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement