Featured Posts

Start Your Journey with Linux Command Line

Image
Start Your Journey with the Linux Command Line: A Comprehensive Guide Whether you are a software developer, system administrator, analytics engineer, or cybersecurity enthusiast, mastering the Linux command line (terminal) is one of the single most effective skills you can acquire. While graphical user interfaces (GUIs) offer visual convenience, the command line interface (CLI) delivers unmatched speed, fine-grained system control, and seamless automation capabilities. Linux Command Line This tutorial breaks down more than 35 core Linux commands into structured, practical modules complete with real-world examples, flags, and command-chaining techniques. By building muscle memory around these fundamentals, you will elevate your daily technical workflow from basic navigation to advanced command orchestration. Why Learn the Command Line? The Linux CLI is not merely a legacy tool—it remains the foundation of modern cloud architecture, server maintenance, DevOps pipelines, and enterp...

Python 2.4.1.6 LAB: A LED Display

Python Code to make a Seven Led Display

Python Code to make a Seven Led Display
Seven LED Display

Exactly, what you see in the picture on top is a sample of a seven led display which uses a decimal number from 0-9 for as many digits as needed. Also, alpha characters (letters and symbols)can be used.

Seven LED Display
Figure.1

Why is it called "Seven Segment"?

Simply because it contains seven elements as shown in Figure.1. The seven segments are arranged as a rectangle of two vertical segments on each side with one horizontal segment on the top, middle, and bottom. The optional decimal point (an "eighth segment", referred to as DP) is used for the display of non-integer numbers.

Seven LED Display
Figure.2

As shown in Figure.2, this is how the numbers are shown. For example, "0" means all segments from A-G are led(shown), "1" means B and C are shown.

And below table shows us the plan of our code

Seven Segments-LED display
Seven Segments-LED display

If you want to get a full idea about How Seven Segment LED Display works, you will find a slideshow in the end of the post.

Solution Code

We will code/draw each segment as "#". Note, the "horizontal segments" have ###, "vertical segments" have #. So, "0" will look like below:

###
#  #
#  #
#  #
###

While "8" will show like this in the console:

###
#  #
###
#  #
###

dict1 = {
    '0': ('###', '# #', '# #', '# #', '###'),
    '1': ('  #', '  #', '  #', '  #', '  #'),
    '2': ('###', '  #', '###', '#  ', '###'),
    '3': ('###', '  #', '###', '  #', '###'),
    '4': ('# #', '# #', '###', '  #', '  #'),
    '5': ('###', '#  ', '###', '  #', '###'),
    '6': ('###', '#  ', '###', '# #', '###'),
    '7': ('###', '  #', '  #', '  #', '  #'),
    '8': ('###', '# #', '###', '# #', '###'),
    '9': ('###', '# #', '###', '  #', '###'),
    '.': ('   ', '   ', '   ', '   ', '  #'),
}
number = input("Please Enter a Positive Number: ")  
def seven_segment(number):
    for i in range(5):
        digits = [dict1[digit] for digit in str(number)]
        print("  ".join(segment[i] for segment in digits))
seven_segment(number)

And here's the Seven-Segment LED system information for further readings:

A LED Display
Seven Segments System



Image Source: https://www.electronics-tutorials.ws/wp-content/uploads/2013/10/segment4.gif?fit=277%2C236?fit=277,226

The Seven-Segment Concept

A seven-segment LED display shows digits and letters by lighting up a fixed set of seven bars, arranged as two vertical segments on each side plus one horizontal segment at the top, middle, and bottom. An optional eighth segment, the decimal point or DP, is used to display non-integer numbers. Because each digit is simply a combination of which segments are turned on, a display can represent all the values from 0 to 9, and with some creativity even letters and symbols.

In this lab the program does not control actual hardware. Instead, it draws the appearance of a seven-segment display in the console using the character #. Horizontal segments are drawn with three hashes, ###, while vertical segments use a single hash, #. Every digit is represented as five rows of text, so the letter 0, for example, is drawn as a top bar, two sides, and a bottom bar.

How the Drawing Code Works

The solution maps each character to a tuple of five strings, one string per row of the display. A dictionary named dict1 holds the drawing rules for the digits 0 through 9 and even the decimal point. Because each entry is a tuple of five rows, drawing the full number is a matter of assembling those rows side by side for every digit.

The function seven_segment(number) loops over the five row positions. For each row index i, it builds a list of the current row for every digit in the number using a list comprehension, then joins those row pieces with two spaces and prints the resulting line. By printing five lines in total, the program reconstructs the entire multi-digit display row by row, exactly as a physical display would show it.

Key Takeaways

  • A seven-segment display uses seven bars plus an optional decimal point to represent digits and letters.
  • Horizontal segments are drawn as ### and vertical segments as #.
  • Each digit is stored as a tuple of five strings, one for each display row.
  • A dictionary maps the characters 0-9 and the decimal point to their row layouts.
  • The function prints one row at a time across all digits, joining each digit's row with spacing.

Frequently Asked Questions

Why does each digit need five rows?

Because the display has three horizontal positions (top, middle, bottom) and two vertical spans, each digit is naturally drawn as five stacked lines, which the console renders as five rows of text.

How is a digit turned into an image?

The code looks up the digit in the dictionary to get its tuple of five rows, then for each row position it joins the matching row from every digit of the number and prints them together as one line.

What does the decimal point add to the display?

The decimal point is an optional eighth segment used to show non-integer numbers. In the post it is drawn as a small hash at the bottom row of a placeholder column.

Can this approach draw letters too?

Yes. Because segments can be combined freely, you can add entries to the dictionary describing how letters and symbols should be drawn, and the same drawing function will display them.

Comments

Popular Posts

PROJECT MAVEN | The Architecture of Algorithmic Warfare

Open Source: The Invisible Engine of Your Daily Life

Data Analysis Roadmap 2026: From Excel Lover to Python-Powered Analyst

Python 4.3.1.10 LAB: Converting fuel consumption

Python for Windows Beginners: Build Your First Automated Workflow in 10 Minutes