Last active
August 25, 2016 05:26
-
-
Save mgardne8/8ef8a6664a736c7db0b243a9450da7e6 to your computer and use it in GitHub Desktop.
Apparently there are only 52 cards in a deck, not 56, who knew
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Lets Play Cards, Class | |
""" | |
from random import shuffle as rshuf | |
class Card(object): | |
def __init__(self, suit=None, value=None): | |
self.suit = suit | |
self.value = value | |
def __str__(self): | |
return '{} of {}'.format(self.value, self.suit) | |
class Deck(object): | |
def __init__(self, shuffled=False): | |
self.cards = [] | |
for suit in ['Spades', 'Clubs', 'Diamonds', 'Hearts']: | |
for value in ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']: | |
self.cards.append(Card(suit=suit, value=value)) | |
if shuffled: | |
self.shuffle() | |
def __str__(self): | |
res = "Deck:\n" | |
for card in self.cards: | |
res += "{} of {}\n".format(card.value, card.suit) | |
return res | |
def shuffle(self): | |
rshuf(self.cards) | |
def draw(self): | |
return self.cards.pop() | |
def insert(self, card=None, place=0): | |
if card is not None: | |
self.cards.insert(place, card) | |
myDeck = Deck(shuffled=True) | |
hand1 = [myDeck.draw() for _ in range(0, 7)] | |
hand2 = [myDeck.draw() for _ in range(0, 7)] | |
print("Hand 1:\n{}\n\n".format([str(card) for card in hand1])) | |
print("Hand 2:\n{}\n\n".format([str(card) for card in hand2])) | |
print(myDeck) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment