''' DS2000 Fall 2024 Sample code from lecture - class to rep a Deck of Cards Attributes: list of cards Methods: __init__, shuffle, deal ''' import random from card import Card NUM_VALUES = 13 SUITS = ["clubs", "diamonds", "hearts", "spades"] class Deck: ''' class for a deck of cards. Attribute: list of Card objects Methods: init, shuffle, deal, str ''' def __init__(self): self.cards = [] self.make_cards() def make_cards(self): ''' create a deck of 52 cards (13 values x 4 suits)''' for i in range(NUM_VALUES): for j in range(len(SUITS)): c = Card(SUITS[j], i + 1) self.cards.append(c) def shuffle(self): ''' shuffle the cards by randomly swapping positions ''' for i in range(len(self.cards)): pos = random.randint(0, len(self.cards) - 1) self.cards[pos], self.cards[i] = self.cards[i], self.cards[pos] def deal(self): ''' deal a card by popping off the deck and returning it ''' if self.cards: return self.cards.pop() return None def __str__(self): ''' print a deck by iterating over and printing suit/val of each card ''' strn = "" for card in self.cards: strn += str(card.val) + " of " + card.suit + "\n" return strn