import random from card import Card class DeckOfCards: """ A deck of playing cards. """ NUMBER_OF_CARDS = 52 # constant number of Cards def __init__(self): """ Constructor of a Deck object. """ self._current_card = 0 self._deck = [] for count in range(DeckOfCards.NUMBER_OF_CARDS): card = Card(Card.FACES[count%13], Card.SUITS[count//13]) self._deck.append(card) def shuffle(self): """ Shuffle deck. """ self._current_card = 0 random.shuffle(self._deck) def deal_card(self): """ @return one Card. """ try: card = self._deck[self._current_card] self._current_card += 1 return card except: return None def __str__(self): """ @return a string representation of the current _deck. """ s = '' for index, card in enumerate(self._deck): s += f'{self._deck[index]:<19}' if (index + 1) % 4 == 0: s += '\n' return s ########################################################################## # (C) Copyright 2019 by Deitel & Associates, Inc. and # # Pearson Education, Inc. All Rights Reserved. # # # # DISCLAIMER: The authors and publisher of this book have used their # # best efforts in preparing the book. These efforts include the # # development, research, and testing of the theories and programs # # to determine their effectiveness. The authors and publisher make # # no warranty of any kind, expressed or implied, with regard to these # # programs or to the documentation contained in these books. The authors # # and publisher shall not be liable in any event for incidental or # # consequential damages in connection with, or arising out of, the # # furnishing, performance, or use of these programs. # ########################################################################## # Additional material (C) Copyright 2024 by Ronald Mak