Created
July 29, 2016 19:46
-
-
Save akueisara/f667e96f5fff4e5d3658db5167b570e1 to your computer and use it in GitHub Desktop.
deckofcard
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
#Create a deck of cards | |
class Card(object): | |
suits = ["spade", "heart", "club", "diamond"] | |
ranks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"] | |
def _init_(self, suit, rank): | |
self.suit = suit | |
self.rank = rank | |
def setSuit(self,suit): | |
self.suit = suit | |
def setRank(self,rank): | |
self.rank = rank | |
def getSuit(self): | |
return Card.suits[self.suit] | |
def getRank(self): | |
return Card.ranks[self.rank] | |
class Cards(object): | |
cards = [] | |
def _init_(self): | |
self.cards = [] | |
def addCard(self, card): | |
self.cards.append(card) | |
def printCard(self): | |
for card in self.cards: | |
print "Card " + card.getSuit() + " " + card.getRank() | |
DeckOfCards = Cards() | |
for i in range(4): | |
for j in range(13): | |
card = Card() | |
card.setSuit(i) | |
card.setRank(j) | |
DeckOfCards.addCard(card) | |
DeckOfCards.printCard() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment