Blackjack Game in Python

UM CSCI 151- Python 2

Assignment Requirements

  • Implement a playable Blackjack game in Python with one player and one dealer.
  • Card, Deck, and Player classes must be created with docstrings.
  • Game must reshuffle deck if it drops below 20 cards.
  • Handle Ace values (1 or 11) appropriately.
  • Implement standard Blackjack rules including:
    • Dealer stands on soft 17
    • Pushes (ties) result in no win/loss
    • 3:2 payout for natural blackjack

Project Summary

This is a console-based version of Blackjack built in Python, simulating classic casino rules. It features a full betting system, natural blackjack detection, reshuffling, and player/dealer interactions.

Key Features

  • Alternating play between player and automated dealer
  • Docstring-compliant Card, Deck, and Player classes
  • Betting system with win/loss/push payouts
  • Dealer AI that respects soft 17
  • Support for reshuffling based on deck size

Sample Code: Card Class


class Card:
    """Represents a single playing card in a standard 52-card deck."""
    def __init__(self, suit, face, value):
        self.suit = suit
        self.face = face
        self.value = value

    def get_value(self):
        return self.value

    def __str__(self):
        return f"{self.face} of {self.suit}"
                

Sample Code: Blackjack Logic


if self.player.blackjack():
    if self.dealer.blackjack():
        print("Push: Both you and the dealer have blackjack.")
        self.player.win(bet_amount)
    else:
        print("Blackjack! You win 3:2 payout.")
        self.player.win(int(bet_amount * 2.5))
                

Technologies Used

  • Python 3
  • OOP (Object-Oriented Programming)
  • Basic input/output and loop control

Reflection

This project solidified my understanding of object-oriented programming and control flow. I implemented recursive logic for Ace evaluation and handled edge cases like dealer ties and re-shuffling logic. In future updates, I could expand the interface to support multiple players or add a graphical UI.