diff --git a/poker_class_version.py b/poker_class_version.py index 2e44718..edd1695 100644 --- a/poker_class_version.py +++ b/poker_class_version.py @@ -92,47 +92,28 @@ class Game: except ValueError: print("Invalid input. Please enter a number between 0 and 3.") - for _ in range(num): - while True: - print("\nYour current hand:\n", player.show_hand()) - user_input = input("Enter a card to replace (e.g., A of Spades): ").strip() + replacements_done = 0 + while replacements_done < num: + print("\nYour current hand:\n", player.show_hand()) + user_input = input("Enter a card to replace (e.g., A of Spades): ").strip() - if ' of ' not in user_input: - print("Invalid format. Use 'Rank of Suit'.") - continue + if ' of ' not in user_input: + print("Invalid format. Use 'Rank of Suit'.") + continue - rank, suit = user_input.split(' of ', 1) - old_card = Card(rank, suit) + rank, suit = user_input.split(' of ', 1) + old_card = Card(rank, suit) - if old_card not in player.hand: - print(f"{old_card} not found in your hand. Please try again.") - continue + if old_card not in player.hand: + print(f"{old_card} not found in your hand. Please try again.") + continue - new_card = self.deck.deal_card() - if player.replace_card(old_card, new_card): - print(f"Replaced {old_card} with {new_card}") - else: - print("Replacement failed unexpectedly.") - break # Exit the inner loop once a valid replacement is made - - for _ in range(num): - print("Your hand:\n", player.show_hand()) - user_input = input("Enter a card to replace (e.g., A of Spades): ").strip() - if ' of ' not in user_input: - print("Invalid format. Use 'Rank of Suit'.") - continue - - rank, suit = user_input.split(' of ', 1) - old_card = Card(rank, suit) - if old_card not in player.hand: - print(f"{old_card} not found in your hand.") - continue - - new_card = self.deck.deal_card() - if player.replace_card(old_card, new_card): - print(f"Replaced {old_card} with {new_card}") - else: - print("Replacement failed.") + new_card = self.deck.deal_card() + if player.replace_card(old_card, new_card): + print(f"Replaced {old_card} with {new_card}") + replacements_done += 1 + else: + print("Replacement failed unexpectedly.") def play(self): print("Initial hands:")