Display Banner - Python Programming Exercise

In this exercise, you will develop a Python program to mimic the basic Unix SysV "banner" utility, capable of displaying large texts. This exercise is perfect for practicing string manipulation and loops in Python. By implementing a program that can display large texts in a banner format, you will gain hands-on experience in handling user input and output in Python. This exercise not only reinforces your understanding of string manipulation but also helps you develop efficient coding practices for managing user interactions.

 Category

Arrays, Lists, and Strings

 Exercise

Display Banner

 Objective

Develop a Python program to mimic the basic Unix SysV "banner" utility, capable of displaying large texts.

 Example Python Exercise

 Copy Python Code
# Define a dictionary for large font representation of characters
banner_font = {
    'A': ['  A  ', ' A A ', 'AAAAA', 'A   A', 'A   A'],
    'B': ['BBBB ', 'B   B', 'BBBB ', 'B   B', 'BBBB '],
    'C': [' CCC ', 'C    ', 'C    ', 'C    ', ' CCC '],
    'D': ['DDDD ', 'D   D', 'D   D', 'D   D', 'DDDD '],
    'E': ['EEEEE', 'E    ', 'EEEEE', 'E    ', 'EEEEE'],
    'F': ['EEEEE', 'E    ', 'EEEEE', 'E    ', 'E    '],
    'G': [' GGG ', 'G    ', 'G  GG', 'G   G', ' GGG '],
    'H': ['H   H', 'H   H', 'HHHHH', 'H   H', 'H   H'],
    'I': [' III ', '  I  ', '  I  ', '  I  ', ' III '],
    'J': ['   J', '   J', '   J', 'J  J', ' JJ '],
    'K': ['K   K', 'K  K ', 'KK   ', 'K  K ', 'K   K'],
    'L': ['L    ', 'L    ', 'L    ', 'L    ', 'LLLLL'],
    'M': ['M   M', 'MM MM', 'M M M', 'M   M', 'M   M'],
    'N': ['N   N', 'NN  N', 'N N N', 'N  NN', 'N   N'],
    'O': [' OOO ', 'O   O', 'O   O', 'O   O', ' OOO '],
    'P': ['PPPP ', 'P   P', 'PPPP ', 'P    ', 'P    '],
    'Q': [' QQQ ', 'Q   Q', 'Q   Q', 'Q  QQ', ' QQQQ'],
    'R': ['RRRR ', 'R   R', 'RRRR ', 'R  R ', 'R   R'],
    'S': [' SSS ', 'S    ', ' SSS ', '    S', ' SSS '],
    'T': ['TTTTT', '  T  ', '  T  ', '  T  ', '  T  '],
    'U': ['U   U', 'U   U', 'U   U', 'U   U', ' UUU '],
    'V': ['V   V', 'V   V', 'V   V', ' V V ', '  V  '],
    'W': ['W   W', 'W   W', 'W M M', 'W M M', 'W   W'],
    'X': ['X   X', ' X X ', '  X  ', ' X X ', 'X   X'],
    'Y': ['Y   Y', ' Y Y ', '  Y  ', '  Y  ', '  Y  '],
    'Z': ['ZZZZZ', '   Z ', '  Z  ', ' Z   ', 'ZZZZZ'],
    ' ': ['     ', '     ', '     ', '     ', '     '],
}

# Main program loop
while True:
    user_input = input("Enter text for banner (or 'exit' to quit): ")
    if user_input.lower() == 'exit':
        break
    
    user_input = user_input.upper()  # Convert text to uppercase for uniformity
    lines = ['' for _ in range(5)]  # Initialize lines for large text (5 lines)
    
    for char in user_input:
        if char in banner_font:
            char_rep = banner_font[char]
            for i in range(5):
                lines[i] += char_rep[i] + '  '  # Add each character's representation with space
    
    # Print the large banner text
    for line in lines:
        print(line)

 Output

Enter text for banner (or 'exit' to quit): Hello
H   H  EEEEE  L      L       OOO  
H   H  E      L      L      O   O 
HHHHH  EEEE   L      L      O   O 
H   H  E      L      L      O   O 
H   H  EEEEE  LLLLL  LLLLL   OOO  

Enter text for banner (or 'exit' to quit): Python
P   P  Y   Y  TTTTT  H   H  OOO   N   N 
P   P  Y Y Y    T    H   H O   O  NN  N 
PPPPP   YYY     T    HHHHH O   O  N N N 
P       Y Y     T    H   H O   O  N  NN 
P       Y   Y    T    H   H  OOO   N   N 

Enter text for banner (or 'exit' to quit): exit

 Share this Python Exercise

 More Python Programming Exercises of Arrays, Lists, and Strings

Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.

  •  Right-Aligned Triangle

    In this exercise, you will develop a Python program that prompts the user for a string and displays a right-aligned triangle. This exercise is perfect for prac...

  •  Text Processing

    In this exercise, you will develop a Python program that prompts the user for a string and performs several transformations. The program will replace all lowercase 'a...

  •  Hierarchical Structures

    In this exercise, you will develop a Python program to store two pieces of data for a person: Name and Date of birth. The Date of birth must be a...

  •  Data Organization

    In this exercise, you will develop a Python program that prompts the user for 10 integer numbers (ranging from -1000 to 1000), sorts them, and displays them in sorted...

  •  Screen Buffer Using 2D Array

    In this exercise, you will develop a Python program that declares a 70x20 two-dimensional array of characters, "draws" 80 letters (X, for example) in random positions...

  •  2D Array: Display Circle

    In this exercise, you will develop a Python program that creates a 70x20 two-dimensional array of characters, "draws" a circle with a radius of 8 inside it, and displ...