avatarJim McAulay🍁 I'm nobody. Are you a nobody too?

Summary

The web content outlines the development of a Python program for generating random bridge hands, with a focus on implementing Unicode symbols for card suits.

Abstract

The article is the second lesson in a series aimed at building a bridge hand generator using Python. It begins by discussing the use of Unicode symbols to represent the four suits in a deck of cards: clubs, diamonds, hearts, and spades. The author, Jim McAulay, provides a draft version of the article series for readers who may have missed the first lesson. He also references a previous article on the use of alt text for images and another on using Unicode symbols in Python, particularly the Dead Man's Hand. The lesson details the code for producing the club symbol using descriptive Unicode references rather than numeric codes for clarity. The author expresses a preference for the all-black versions of the card symbols over those with white centers. A link to the Unicode Code Charts is provided for further exploration of Unicode symbols. The article concludes with the current state of the Python program code, which includes the import of the shuffle module and the assignment of Unicode symbols to constants representing each suit. Additionally, McAulay humorously comments on the financial impact of his daughter leaving for university and includes a "Buy me a coffee" image for support.

Opinions

  • The author prefers using descriptive Unicode references for clarity over numeric codes.
  • Jim McAulay favors the aesthetic of all-black card symbols over those with white centers.
  • McAulay uses a light-hearted remark to express the mixed emotions of his daughter's departure to university, highlighting both pride and the financial aspect.
  • The provision of a draft version of the article series indicates the author's consideration for readers who may have joined the series midway.
  • The inclusion of a "Buy me a coffee" image suggests that McAulay appreciates and possibly relies on reader support for his work.

Building A Bridge Hand Generator With Python Lesson 2

Using unicode

Photo by Element5 Digital on Unsplash

This is a continuation of an article that I began yesterday. The final article will contain 6 or 7 parts. We will be going through the creation of a program with python to created randomly selected bridge hands step by step. The first step was to import the shuffle module which we will be using to shuffle the deck of cards.

The next step is to add unicode symbols.

If you missed the first lesson rather than going back to it, I have created a draft version which at this point will have the first two lessons. I will be updating daily. It won’t be published until the series is complete. You can however view it here.

I wrote an article about using draft versions to provide more detail for images. From the link below scroll down to the picture of the young man dressed in green and click on the image.

To create the symbols for our bridge program we are going to by using unicode symbols.

♣ ♦ ♥ ♠

What are unicode symbols?

I wrote about unicode symbols in the following article:

Here is the code to produce the club symbol:

CLUBS = (u'\N{black club suit}')
u'\N{named suit}' gives named unicode
'u\(hex number)' gives unnamed unicode

Numeric codes in unicode are 4 digit base 16 numbers. The codes for the card suits just happen to resemble the base 10 numbers that you are familiar with. A8B0 for example would be a legitimate hexadecimal number.

It is a python convention to use all caps for constants. CLUBS is prefered over clubs.

I could have used a numeric reference for the symbols hower when descriptive references are available it is much clearer to use them. For example

CLUBS = (u'\N{black club suit}')# is much clearer than
CLUBS = ('u\2663')

The playing card symbols are available with a black center or with a white center. I could have used white centers to represent the red cards however I prefer the all black version.

I think that ♣ ♦ ♥ ♠ looks better than ♣ ♢ ♡ ♠

Here is a link to the Unicode site

Here is the code for our program so far:

from random import shuffle
CLUBS = (u'\N{black club suit}')
DIAMONDS  = (u'\N{black diamond suit}')
HEARTS = (u'\N{black heart suit}')
SPADES = (u'\N{black spade suit}')

Jim McAulay🍁 says: “When my daughter left for university I felt a great emptiness in my life, specifically in my checking account.”.

Buy me a coffee

102–103

Technology
Python
Jim Mcaulay
Illumination
Humour
Recommended from ReadMedium
avatarJudy Haratz Cohen
Fix That Window Shade

Teacher evaluations

3 min read