Package: playingcards.py
playingcards.pyAn Advanced Python Playing Card Module that makes creating playing card games simple and easy!FeaturesEasy to Understand Class ObjectsASCII Card ImagesCard ComparisonsDuplicate Prevention within DecksInstallationRequires Python 3.6 and aboveYou can install the module fromPyPIor by using pip.# Linux/MacOSpip3installplayingcards.py# Windowspipinstallplayingcards.pyHow To UseThis module introduces three class objects:CardCollection,DeckandCard.Differences Between ClassesCardis a class that contains properties that are found on your everyday playing card, i.e. rank and suit.CardCollectionis a class used to construct various types of card collections. For example, you could use it to construct a class for a "Hand" of cards.Deckis class constructed from the CardCollection class. It contains 52 upon its initialization and has member functions related to drawing cards and attributes referring to the numeric amounts in the deck.Drawing CardsTheDeckclass can be called with thedraw_card()function to draw a card object. Additionally,draw_n()can be used to draw multiple cards at once and be returned as a CardCollection object.Generating a card by only using theCardclass happpens when you instantiate it.fromplayingcardsimportDeck,Card# Card Generated Using Deckplayer_deck=Deck()player_card=player_deck.draw_card()player_hand=player_deck.draw_n(5)# Card Generated From Instantiationplayer_card_2=Card()Class Methods & AttributesCardAttributesdeckDeck- Returns a Deck object if the card was drawn from a deck.Default: None.suitint- Returns an integer that corresponds with the card's suit.suit_namestr- Returns a string containing the converted suit name.valueint- Returns an integer of the card's face value.rankUnion[str,int]- Returns a string if the value can be converted into a word value (Ex. 11 -> Jack). Defaults to returning an integer if its not applicable (Ex. 2 -> 2).namestr- Returns a string containing the full name of the card. This prints out the rank and the suit of the card. (Ex. Ace of Spades, 3 of Hearts)imgstr- Returns a string that contains an ASCII image of the card with the corresponding suit symbol.CardCollectionAttributescardsList[Card]- Returns a list of Card objects.maximumint- Returns the maximum number of cards that can be held in the collection.orderedbool- Returns a boolean value that indicates whether the collection is ordered or not.Methodsadd_cards(cards,position,random) - Adds cards to the collection.Parameterscards(List[Card]) - A list of Card objects to be added to the collection.position(int) - The position in the collection to add the cards.random(bool) - A boolean value that indicates whether the cards should be added in a random position.ReturnsNoneremove_card(cards,position) - Removes a card from the collection.Parameterscards(List[Card]) - A list of Card objects to be removed from the collection.position(int) - The position in the collection to remove the card.ReturnsNoneorder_cards() - Orders the cards in the collection.ParametersNoneReturnsNoneshuffle() - Shuffles the cards in the collection.ParametersNoneReturnsNoneDeck(inheritsCardCollectionmethods & attributes)Attributescardslist- Returns a list containing the class objects of each drawn card.drawnint- Returns an integer of the amount of cards that have been drawn.remainingint- Returns an integer amount of the remaining cards that can be drawn.Methodsdraw_card() - Draws a card from the top of the deck.ParametersNoneReturnsCarddraw_n(n) - Draws a number of cards from the top of the deck.Parametersn(int) - The number of cards to draw.ReturnsCardCollectionObject Initialization ArgumentsA card object can be instantiated with preconceived values instead of using a random number generator.Suits are ordered numerically from 0-3.0:Spades1:Clubs2:Hearts3:DiamondsValues are ordered numerically from 1-13.1:Ace2-10:Face Value11:Jack12:Queen13:Kingplayer_card=Card(value=11,suit=1)print(player_card)>>JackofClubsprint(player_card.value)>>11print(player_card.suit_name)>>Clubsprint(player_card.rank)>>Jackprint(player_card.img)>>*---*|♣||J||♣|*---*Card ComparisonsThe card objects feature comparison features which allows theirvaluesto be compared.When checking for equivalency, it only checks the value of the card,not the suits.card_1=Card(value=8,suit=0)card_2=Card(value=12,suit=2)card_3=Card(value=8,suit=3)print(card_1<card_2)>>Trueprint(card_3==card_1)# Returns True even if the suit is different>>TrueContributingSeeCONTRIBUTING.mdAcknoledgementsTheCardCollectionobject was inspired by@mitchr1598whose playingcards project utilized.