Implement card removal functionality and update player 1's hand management

This commit is contained in:
Donald Calloway 2025-09-15 11:21:40 -07:00
parent 4a36bfdfca
commit c2d5d799fc

View File

@ -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()