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

Comments

Popular posts from this blog

فرصتك للدراسة في ألمانيا: منحة ممولة بالكامل لطلاب الدراسات العليا

How to Deactivate Screen Reader in Kali Linux

Murphy's Law: Expect the Unexpected

Python 3.2.1.14 LAB: Essentials of the while loop

7 Reasons Why You Need to Learn English

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

15 Python Builtin-Functions You Need to Master as a Beginner

Prefixes vs Suffixes ? What are they?

Python 4.3.1.7 LAB: How many days: writing and using your own functions

Python 4.3.1.6 LAB: A leap year: writing your own functions