diff --git a/poker_class_version.py b/poker_class_version.py index 90aef3b..b341be4 100644 --- a/poker_class_version.py +++ b/poker_class_version.py @@ -82,22 +82,29 @@ class Game: self.player2 = Player("Player 2", self.deck) def prompt_card_replacement(self, player: Player): - num = int(input(f"{player.name}, how many cards do you want to pull? (0-3): ")) - if not (0 <= num <= 3): - print("Invalid number. Choose between 0 and 3.") - return + while True: + try: + num = int(input(f"{player.name}, how many cards do you want to pull? (0–3): ")) + if 0 <= num <= 3: + break + else: + print("Invalid number. Please choose between 0 and 3.") + except ValueError: + print("Invalid input. Please enter a number between 0 and 3.") 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.") + 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}")