diff --git a/Project 1/Deck.py b/Project 1/Deck.py index d2d5fd8..89d7a6d 100644 --- a/Project 1/Deck.py +++ b/Project 1/Deck.py @@ -27,12 +27,18 @@ class Deck: self._cards.append(Card(suit, value)) #creates a standard 52-card deck def shuffle(self): + """ + Shuffles the deck of cards using the Fisher-Yates algorithm. This algorithm iterates through the deck and swaps each card with a randomly selected card from the remaining unshuffled portion of the deck. After shuffling, it resets the next card index to 0. + """ for i in range(len(self._cards)): #iterates through each card in the deck j = random.randrange(i, len(self._cards)) #selects a random index from i to the end of the deck self._cards[i], self._cards[j] = self._cards[j], self._cards[i] #Shuffles the deck self._next_card = 0 #Resets the next card index after shuffling. def deal(self): + """ + Deals the next card from the deck. Returns None if there are no cards left to deal. + """ if self._next_card >= len(self._cards): return None #Returns None if there are no cards left to deal. card = self._cards[self._next_card] diff --git a/Project 1/test.py b/Project 1/test.py new file mode 100644 index 0000000..88bef15 --- /dev/null +++ b/Project 1/test.py @@ -0,0 +1,2 @@ +for i in range (0, 10): + print(i) \ No newline at end of file diff --git a/Project 2/Deck.py b/Project 2/Deck.py index f63a50e..8302cec 100644 --- a/Project 2/Deck.py +++ b/Project 2/Deck.py @@ -26,12 +26,18 @@ class Deck: self._cards.append(Card(suit, value)) #creates a standard 52-card deck def shuffle(self): + """ + Shuffles the deck of cards using the Fisher-Yates algorithm. This algorithm iterates through the deck and swaps each card with a randomly selected card from the remaining unshuffled portion of the deck. After shuffling, it resets the next card index to 0. + """ for i in range(len(self._cards)): #iterates through each card in the deck j = random.randrange(i, len(self._cards)) #selects a random index from i to the end of the deck self._cards[i], self._cards[j] = self._cards[j], self._cards[i] #Shuffles the deck self._next_card = 0 #Resets the next card index after shuffling. def deal(self): + """ + Deals the next card from the deck. Returns None if there are no cards left to deal. + """ if self._next_card >= len(self._cards): return None #Returns None if there are no cards left to deal. card = self._cards[self._next_card] @@ -41,6 +47,13 @@ class Deck: def number_of_cards(self) -> int: return len(self._cards) - self._next_card #Returns the number of remaining cards in the deck. + def __repr__(self) -> str: + """ + Returns a string representation of the entire deck, + with one card per line. + """ + return "\n".join(str(card) for card in self._cards) + if __name__ == "__main__": deck = Deck() deck.shuffle() #Calls the shuffle method to randomize the deck. diff --git a/Project 2/__pycache__/Card.cpython-314.pyc b/Project 2/__pycache__/Card.cpython-314.pyc index a5c9f2b..6881390 100644 Binary files a/Project 2/__pycache__/Card.cpython-314.pyc and b/Project 2/__pycache__/Card.cpython-314.pyc differ diff --git a/Project 2/__pycache__/Deck.cpython-314.pyc b/Project 2/__pycache__/Deck.cpython-314.pyc index a094663..d667d5f 100644 Binary files a/Project 2/__pycache__/Deck.cpython-314.pyc and b/Project 2/__pycache__/Deck.cpython-314.pyc differ diff --git a/Project 2/__pycache__/Solitaire.cpython-314.pyc b/Project 2/__pycache__/Solitaire.cpython-314.pyc index f81fc9d..ccfec9e 100644 Binary files a/Project 2/__pycache__/Solitaire.cpython-314.pyc and b/Project 2/__pycache__/Solitaire.cpython-314.pyc differ diff --git a/Project 2/__pycache__/main.cpython-314.pyc b/Project 2/__pycache__/main.cpython-314.pyc new file mode 100644 index 0000000..08bdcaa Binary files /dev/null and b/Project 2/__pycache__/main.cpython-314.pyc differ diff --git a/Project 2/__pycache__/utilities.cpython-314.pyc b/Project 2/__pycache__/utilities.cpython-314.pyc new file mode 100644 index 0000000..407eddc Binary files /dev/null and b/Project 2/__pycache__/utilities.cpython-314.pyc differ diff --git a/Project 2/utilities.py b/Project 2/utilities.py index ce7923e..fe6cd15 100644 --- a/Project 2/utilities.py +++ b/Project 2/utilities.py @@ -41,3 +41,5 @@ def test_sum_cards(): ] assert sum_cards_iter(cards) == 21 assert sum_cards_recursive(cards) == 21 + +test_sum_cards() \ No newline at end of file