Cards deck problem

Arun Nair nairarunv at gmail.com
Thu Oct 26 05:27:16 EDT 2006


Can any one help me with this im not getting it even after reading
books because there is not much of discussion anywhere

a>
 Implement a calss that represents a playing card.  The class should
implement the following methods:
_ _ init _ _ (self, rank, suit) Creates a card.
rank is an integer in range of 1 to 13 (Ace:1, King 13), suit is a
character in set {'h','d','c','s'}
getRank(self) Returns the rank of the card
getSuit(self) Returns the suit of the card
BJValue(self) Returns the 'Blackjack Value' of the card (Ace:1, Face
card:10)
_ _ str _ _ (self) Returns a string naming the card. For example: 'Ace
of Spades'

Test your class by writing a 'test harness' that generates 'n' randomly
generated cards, where 'n' is supplied by the user.  Print out the
string associated with each card and it's 'Blackjack value'


b>
Extend the card class to display in a graphics window.  the new class
should support the following method: draw(self, win, center) Draws a
card in a window.
Use the extended class to display a hand of five random cards.


c> Write a program that creates a list of card objects as above and
print out the cards grouped by suit and in rank order in each suit.
the program should read the values for the list of cards from a file,
where each line in the file specifies a single card with the rank and
then the suit separated by a space. Hint: sort the list first by rank,
and then by suit.


d> Create a new class deck that represents a pack of 52 cards.  Which
supports the following methods:

_ _init_ _ (self) - Creates a deck of cards in standard order.
shuffle(self) - Randomizes the order of the cards
dealCard(self) - Returns a single card from the top of the deck, and
removes the card from the deck.
cardsLeft(self) - Returns the number of cards left in the deck.
Test your class by having it deal out a sequence of 'n' cards where 'n'
is a number input by the user.  The program should either print out the
cards, or display them in a window.

Your urgent and quick reply help will be appreciated the most.

Arun Nair




More information about the Python-list mailing list