geekcomputers/Python · error · ValueError
The deck is empty; cannot draw more cards
Error message
The deck is empty; cannot draw more cards
What it means
Raised by drawCards in the UNO CLI when the deck list runs out while trying to pop the requested number of cards. The code converts the underlying IndexError from unoDeck.pop(0) into a ValueError with an explanatory message.
Source
Thrown at BoardGame-CLI/uno.py:69
"""Draw card function that draws a specified number of cards off the top of the deck
Parameters: numCards -> integer
Return: cardsDrawn -> list
"""
def drawCards(numCards: int) -> List[str]:
"""
Draw a number of cards from the top of the global `unoDeck`.
Raises ValueError if the deck runs out of cards.
"""
cardsDrawn: List[str] = []
for x in range(numCards):
try:
cardsDrawn.append(unoDeck.pop(0))
except IndexError:
raise ValueError("The deck is empty; cannot draw more cards")
return cardsDrawn
"""
Print formatted list of player's hand
Parameter: player->integer , playerHand->list
Return: None
"""
def showHand(player: int, playerHand: List[str]) -> None:
print("Player {}'s Turn".format(players_name[player]))
print("Your Hand")
print("------------------")
y = 1
for card in playerHand:
print("{}) {}".format(y, card))
y += 1View on GitHub (pinned to 40f4cd2652)
Solutions
- Before drawing, reshuffle the discard pile back into the deck when it gets low (standard UNO rule)
- Check len(unoDeck) >= numCards before calling drawCards and rebuild the deck if not
- Catch the ValueError in main and trigger a deck-reshuffle then retry the draw once
- Reduce numCards to what remains if the game is ending
Example fix
// before
cards = drawCards(unoDeck, 2)
// after
if len(unoDeck) < 2:
unoDeck = reshuffle_discard(discard_pile)
cards = drawCards(unoDeck, 2) Defensive patterns
Strategy: fallback
Validate before calling
def safe_draw(unoDeck, discard, n):
if len(unoDeck) < n:
unoDeck.extend(reshuffle(discard))
return drawCards(unoDeck, n) if len(unoDeck) >= n else None Try / catch
try:
cards = drawCards(unoDeck, n)
except ValueError:
unoDeck.extend(reshuffle_discard_pile())
cards = drawCards(unoDeck, n) Prevention
- Recycle the discard pile into the deck when it drops below a threshold (e.g. 10 cards)
- Check len(unoDeck) >= requested count before drawing
- Cap penalty draws at the remaining deck size
When it happens
Trigger: Calling drawCards(numCards) when len(unoDeck) < numCards, typically near the end of a long game where the draw pile was never replenished from played/discarded cards.
Common situations: Long UNO games where the deck isn't recycled; dealing at startup with a deck that was already depleted or mis-shuffled; drawing penalty cards (e.g. after a Draw Four) at the very end of the deck.
Related errors
- Parameter n must be greater or equal to one.
- Your integer should bigger than 0
- Your chips should between 1 -
- Not enough chips
- Player BUST
AI-assisted analysis of geekcomputers/Python@40f4cd2652 (2026-08-27).
Data as JSON: /api/errors/f00f43b1a03f57c2.
Report an issue: GitHub.