deck_of_cards package¶
Module contents¶
A Python Implementation Of A Deck of Cards
Submodules¶
deck_of_cards.card module¶
This module provides the Card object.
This module also has 5 constant attributes that help validate or string format
the Card object: POSSIBLE_SUIT, POSSIBLE_RANK,
, JOKER_SUIT, JOKER_RANK, and RANK_TRANSLATION
-
class
deck_of_cards.card.Card(rank, suit)[source]¶ Bases:
objectA Card object
Parameters: - rank (int) – a rank in
POSSIBLE_RANKorJOKER_RANK - suit (str) – a case-independent string in
POSSIBLE_SUITorJOKER_SUIT
Raises: ValueError
-
__eq__(other)[source]¶ Override equality method
Returns: True if two objects are cards and have the same _rankand_suitReturn type: bool
-
__repr__()[source]¶ This method returns an unambigious string representation of the card object
Returns: unambigious string represenation of card object Return type: str
-
__str__()[source]¶ This method returns a nice string representation of the card object
useful in printing card object as “%s”
Returns: human readable string represenation of card object Return type: str
-
_rank= None¶ Holds an integer which represents the card rank
-
_suit= None¶ Holds the suit as a lowercase string
- rank (int) – a rank in
-
deck_of_cards.card.JOKER_RANK= 0¶ a number representing the Joker’s rank
-
deck_of_cards.card.JOKER_SUIT= 'joker'¶ a string representing the Joker’s suit
-
deck_of_cards.card.POSSIBLE_RANK= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]¶ an array with the possible ranks
-
deck_of_cards.card.POSSIBLE_SUIT= ['hearts', 'diamonds', 'spades', 'clubs']¶ an array with all the possible suit strings
-
deck_of_cards.card.RANK_TRANSLATION= {1: 'ace', 11: 'jack', 12: 'queen', 13: 'king'}¶ a dictionary which translates the special face cards to strings
deck_of_cards.deck module¶
This module provides the Deck object
-
class
deck_of_cards.deck.Deck(with_jokers=True)[source]¶ Bases:
objectA Deck object
A new deck starts out ordered.
If jokers are included, contains (2 + 4 * 13)
deck_of_cards.card.CardobjectsIf no jokers are included, contains (4 * 13)
deck_of_cards.card.CardobjectsParameters: with_jokers (bool) – include jokers if True -
_cards= []¶ an array of unused
deck_of_cards.card.Cardobjects that are waiting to be dealt
-
_discarded_cards= []¶ an array of discarded
deck_of_cards.card.Cardobjects
-
_in_play_cards= []¶ an array of
deck_of_cards.card.Cardobjects that have been dealt
-
_with_jokers= True¶ a boolean to represent if jokers exist in deck
-
check_deck()[source]¶ Check to make sure all the cards are accounted
Returns: True if all cards are accounted Return type: bool
-
deal()[source]¶ Deals a single
deck_of_cards.card.Cardfrom_cardsRaises an IndexError when
_cardsis emptyReturns: a single deck_of_cards.card.CardReturn type: deck_of_cards.card.CardRaises: IndexError
-
discard(cards)[source]¶ Remove cards from the
_in_play_cardsarray and add them to_discarded_cardsarrayRaises a ValueError when trying to discard a card that does not exist in
_in_play_cards.Parameters: cards (array) – an array of deck_of_cards.card.Cardobjects or a singledeck_of_cards.card.CardRaises: ValueError
-
-
deck_of_cards.deck.LOGGER= <logging.Logger object>¶ a logger object