Entry 6026
examples.py
Submitted by anonymous
on Aug. 13, 2010 at 10:39 p.m.
Language: Python. Code size: 2.5 KB.
''' Examples Using Card and Deck Classes: ------------------------------------------------------------------------ ******************************************************************** Code by Julien McArdle for <removed> job application. Python code tested with Python 2.6.5 under Ubuntu Linux. Julien can be contacted at the following address: julien@jmcardle.com The code and documentation on the card classes are found in the accompanying file, "card_classes.py". ******************************************************************** ''' from card_classes import stackOfCards, card # Let's create a new deck of cards. deckOfCards = stackOfCards(stackOfCards().fullOrderedDeck()) # Let's list off what is in the deck of cards. print("CARDS IN THE STACK") for card in deckOfCards.showCards(): print(card.printCard()) # Let's shuffle the cards and print off what's in the stack. print("\n\nSHUFFLED CARDS IN THE STACK") deckOfCards.shuffleCards() for card in deckOfCards.showCards(): print(card.printCard()) # Let's deal the shuffled cards, and see what each player has. # We will deal 4 cards to 5 players. playerCards = deckOfCards.dealCards(5,4) for player in range(4): print("\n\nPLAYER " + str(player+1) + "'S CARDS") for card in playerCards[player].showCards(): print(card.printCard()) # Let's write out what the cards left in the deck are. print("\n\nCARDS LEFT IN THE STACK") for card in deckOfCards.showCards(): print(card.printCard()) # Let's count how many cards are left in the deck. print("\n\n" \ "There are " + str(deckOfCards.numberOfCards()) + " cards left in "\ "the stack of cards.") # Let's grab the top card in the deck. exampleCard = deckOfCards.takeTopCard() print("The suit of the top card is " + exampleCard.printSuit() + " and the " \ "rank of the card is " + exampleCard.printRank() + ". \n" \ "It has been removed from the deck of cards.") # Let's cut the remaining cards into two new stacks of cards. stackOne, stackTwo = deckOfCards.cutCards() print("\n\nCARDS IN THE FIRST DECK (" + str(stackOne.numberOfCards()) + " cards)") for card in stackOne.showCards(): print(card.printCard()) print("\n\nCARDS IN THE SECOND DECK (" + str(stackTwo.numberOfCards()) + " cards)") for card in stackTwo.showCards(): print(card.printCard())
This snippet took 0.01 seconds to highlight.
Back to the Entry List or Home.