Debugging in Python, part 9: Hands and Decks

MP 150: Modeling a hand of playing cards, and a deck as well.

Note: This post is part of an ongoing series about debugging in Python. The posts in this series will only be available to paid subscribers for the first 6 weeks. After that they will be available to everyone. Thank you to everyone who supports my ongoing work on Mostly Python.

We want to look at logical errors, but we need an appropriate codebase to practice against. In the last post we modeled a playing card; in this post we'll build out models for a hand of cards, and a deck of cards. We'll be able to use this codebase in the next few posts to look at a number of interesting logical errors.

Modeling a hand of cards

In many card games, players are dealt a hand of cards. A lot of games start with 5 or 7 cards, but the number of cards in a hand can vary widely.

Here's a first pass at the Hand class:

This post is only available to paid subscribers at the moment. It will be available to everyone 6 weeks after posting. If you'd like to continue reading now, please support my work by signing up for a paid subscription.

Paid subscription options