geekcomputers/Python · warning · ValueError

Player BUST

Error message

Player BUST

What it means

Raised in card_manage when the player draws a card (Hit or Double-down) and their point total exceeds BLACK_JACK (21). It is control flow used to end the round with a player bust, not an infrastructure failure. The caller (play) is expected to catch it and settle the bet.

Solutions

  1. Catch ValueError in the calling play loop and settle the round as a player loss
  2. Before hitting, check the current total and consider standing on 17+
  3. Use is_point to inspect the hand total before requesting Hit/Double-down

Example fix

// before
self.card_manage()
// after
try:
    self.card_manage()
except ValueError as e:
    # round ends: player bust, settle bet
    self.settle(busted=str(e))
Defensive patterns

Strategy: try-catch

Validate before calling

if choice in ('Hit','Double-down') and player.is_point('>', BLACK_JACK - 5):
    # risky draw ahead; consider standing
    pass

Try / catch

try:
    self.card_manage()
except ValueError as e:
    if 'Player BUST' in str(e):
        self.settle(player_wins=False)

Prevention

When it happens

Trigger: self.choice in ('Hit','Double-down') followed by player.obtain_card(deck) making player.is_point('>', 21) true. Card_manage is invoked from play after each player decision.

Common situations: Simulating many rounds where a hit on a stiff hand (12-16) exceeds 21; forgetting that Double-down also draws a card and can bust.

Related errors


AI-assisted analysis of geekcomputers/Python@40f4cd2652 (2026-08-27). Data as JSON: /api/errors/cc9b592f35262f1b. Report an issue: GitHub.

Appendix: source

Thrown at BlackJack_game/blackjack_simulate.py:550

                prompt="Insurance amount >> ",
                general_err=err,
            )
            self.player.chips.insurance = pay_ins

        if self.choice == "Double-down":
            try:
                self.player.chips.double_bet()
            except ValueError as e:
                print(e)
        self.player.refresh_prompt()
        if self.choice in ("Insurance", "Double-down", "Surrender"):
            self.go_on = False

    def card_manage(self):
        if self.choice in ("Hit", "Double-down"):
            self.player.obtain_card(self.deck)
            if self.player.is_point(">", BLACK_JACK):
                raise ValueError("Player BUST")
            else:
                self.dealer.strategy_trigger(self.deck)
                if self.dealer.is_point(">", BLACK_JACK):
                    raise ValueError("Dealer BUST")
        elif self.choice != "Surrender":
            if not self.player.chips.is_insurance:
                self.dealer.strategy_trigger(self.deck)
                if self.dealer.is_point(">", BLACK_JACK):
                    raise ValueError("Dealer BUST")

        self.dealer.showing()
        self.player.showing()
        if self.choice in ("Double-down", "Stand"):
            self.go_on = False

    def is_surrender(self):
        if self.choice == "Surrender":
            self.player.speak("Sorry, I surrender....\n")

View on GitHub (pinned to 40f4cd2652)