VOOZH about

URL: https://www.geeksforgeeks.org/python/blackjack-console-game-using-python/

⇱ Blackjack console game using Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Blackjack console game using Python

Last Updated : 18 Apr, 2026

Blackjack, also known as Twenty-One, is a popular card game played between a player and a dealer. The objective of the game is to get a total card value as close to 21 as possible without exceeding it. This game is a great example to understand how basic Python concepts like lists, loops, functions, and conditional statements work together.

Rules of Blackjack Game

Let's first understand the game's rules before writing the blackjack console game code.

  1. Each player and the dealer get two cards initially.
  2. The player can choose to "play" (take another card) or "stop" (hold the current score).
  3. Face cards (Jack, Queen, King) are worth 10 points.
  4. Aces can be worth 11 points.
  5. Exceeding 21 points results in an automatic loss.
  6. The winner is the player with the highest score ≤ 21 after comparing with the dealer.

Step-by-Step Implementation

Step 1.Import Required Module: The random module is used to shuffle the deck of cards.

Step 2.Create a Deck of Cards: Create a list of cards and suits, then combine them as tuples for the full deck.

Step 3. Define Card Values: The below function assigns points to each card.

Step 4. Shuffle the Deck and Deal Initial Cards: Shuffle the deck and deal two cards each to the player and dealer.

Step 5. Player’s Turn: The player can hit (draw a card) or stand (stop) until they stop or exceed 21 points.

Step 6. Dealer’s Turn: The dealer draws cards until reaching 17 or higher.

Step 7. Determine the Winner: Compare scores to determine the winner.

Complete Code

Comment
Article Tags: