From c2d5d799fc4821db0f9032333479ddce24c4d926 Mon Sep 17 00:00:00 2001 From: Donald Calloway Date: Mon, 15 Sep 2025 11:21:40 -0700 Subject: [PATCH] Implement card removal functionality and update player 1's hand management --- poker.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/poker.py b/poker.py index 978e2cb..ebcd769 100644 --- a/poker.py +++ b/poker.py @@ -42,6 +42,12 @@ def hand_rank(hand): def show_hand(hand): return '\n '.join([f"{rank} of {suit}" for rank, suit in hand]) +def remove_card_from_hand(hand, card): + if card in hand: + hand.remove(card) + return True + return False + def main(): deck = create_deck() random.shuffle(deck) @@ -50,7 +56,18 @@ def main(): print("Player 1's hand:\n", show_hand(player1)) print() print("Player 2's hand:\n", show_hand(player2)) - rank1 = hand_rank(player1) + + + pull_card_player1 = input("Player 1, enter a card to pull from your hand (e.g., 'A of Spades', or 'none'): ") + if 'none' not in pull_card_player1.lower(): + rank, suit = pull_card_player1.split(' of ') + if remove_card_from_hand(player1, (rank, suit)): + player1.remove((rank, suit)) + print("Player 1 pulled", rank, "of", suit, "from his hand.") + else: + print("Card not found in Player 1's hand.") + + rank1 = hand_rank(player1) rank2 = hand_rank(player2) if rank1 > rank2: print("Player 1 wins! with rank:", rank1) @@ -61,6 +78,7 @@ def main(): else: print("It's a tie!") print("Both players have rank:", rank1) + if __name__ == "__main__": main() \ No newline at end of file