Barcode Generator – Using Python

barcodeFor this challenge we are investigating how barcodes are produced. Though there are different standards to produce barcodes, they all follow a similar approach based on binary code!

Did you know?

On a barcode the pattern made using black and white lines is in fact binary code! A black line represents a 1 and a white line a 0.

So the following binary code “0101” consists of a thin white line, a thin black line, a thin white line and a thin black line.

The following binary code “1110” however consists of a large black line (as thick as 3 lines) and a thin white line.

So to produce our own simplified bar codes all we need to know is convert each digit of the actual number into binary (using 4 digit binary codes, aka a nibble)

Decimal Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001

Using Python to generate random barcodes

Your Challenge

Adapt this script to ask the end-user to enter their initials. Use the ASCII table to convert these initials into ASCII and then into binary code to then generate a barcode matching those initials.

Share Button
Posted in Computer Science, Python - Advanced, Python Challenges Tagged with:

Our Latest Book