Print with your own font using Python
Given a word or name, the task is to print it in a custom-designed font using Python. Each character of the input is mapped to a pattern made of symbols, allowing you to print text in your own creative style. For example:
Input: ROOT
Output:
..######..
..#....#..
..#.##...
..#...#...
..#....#..
..######..
..#....#..
..#....#..
..#....#..
..######..Explanation: Each character of "ROOT" is matched with its ASCII-art pattern and printed line by line.
Now, let’s explore different methods to print custom fonts using Python.
Using Pre-Structured ASCII Rows
This method stores every character’s ASCII-art as a list of rows, enabling clean horizontal alignment. It prints the custom font by assembling the output row by row, which looks neat and scales well.
font = { "G":["..######..","..#.......","..#.####..","..#....#..","..#####..."],
"E":["..######..","..#.......","..#####...","..#.......","..######.."],
"K":["..#...#...","..#..#....","..##......","..#..#....","..#...#..."] }
name = "GEEK"
rows = len(next(iter(font.values())))
for i in range(rows):
for ch in name:
print(font[ch][i], end=" ")
print()
Output:
..######.. ..######.. ..######.. ..#...#...
..#....... ..#....... ..#....... ..#..#....
..#.####.. ..#####... ..#####... ..##......
..#....#.. ..#....... ..#....... ..#..#....
..#####... ..######.. ..######.. ..#...#...
Explanation:
- font = {...} font maps each letter to a list of strings, one string per row.
- rows = len(next(iter(font.values()))) finds number of rows per letter.
- for i in range(rows): loop over row index (print row 0 for all letters, then row 1, ...).
- for ch in name: loop over letters in the word.
- print(font[ch][i], end=" ") print the i-th row of the letter with a space after it.
Using Dictionary Mapping
This method stores each character as a full block string. It prints each block as soon as the character appears.
font = { "G":"..######..\n..#.......\n..#.####..\n..#....#..\n..#####...",
"E":"..######..\n..#.......\n..#####...\n..#.......\n..######..",
"K":"..#...#...\n..#..#....\n..##......\n..#..#....\n..#...#..." }
name = "GEEK"
for ch in name:
print(font.get(ch, "Character not available"))
Output:
..######..
..#.......
..#.####..
..#....#..
..#####...
..######..
..#.......
..#####...
..#.......
..######..
..######..
..#.......
..#####...
..#.......
..######..
..#...#...
..#..#....
..##......
..#..#....
..#...#...
Explanation:
- font= {...} maps each letter to a single multi-line string (the whole block).
- name = "GEEK" input word.
- for ch in name: iterate over each letter.
- print(art.get(ch, "Character not available")) fetch and print the block; fallback if missing.
Using User-Defined Function
This method defines a function that prints the pattern for each character by using if / elif checks.
def show(c):
c = c.upper()
if c == "G":
print("..######..\n..#.......\n..#.####..\n..#....#..\n..#####...")
elif c == "E":
print("..######..\n..#.......\n..#####...\n..#.......\n..######..")
elif c == "K":
print("..#...#...\n..#..#....\n..##......\n..#..#....\n..#...#...")
name = "GEEK"
for ch in name:
show(ch)
print()
Output:
..######..
..#.......
..#.####..
..#....#..
..#####...
..######..
..#.......
..#####...
..#.......
..######..
..######..
..#.......
..#####...
..#.......
..######..
..#...#...
..#..#....
..##......
..#..#....
..#...#...
Explanation:
- def show(c): defines show, which prints the ASCII block for c.
- c = c.upper() normalize to uppercase.
- if c == "G": ... elif c == "E": ... choose the right block and print() it.
- for ch in name: loop letters in the word.
- show(ch) print letter's block.
Using Multiple If-Else Blocks
This traditional method manually checks each character and prints its pattern. It is clear but repetitive.
name = "GEEK"
for ch in name:
if ch == "G":
print("..######..\n..#.......\n..#.####..\n..#....#..\n..#####...")
elif ch == "E":
print("..######..\n..#.......\n..#####...\n..#.......\n..######..")
elif ch == "K":
print("..#...#...\n..#..#....\n..##......\n..#..#....\n..#...#...")
print()
Output:
..######..
..#.......
..#.####..
..#....#..
..#####...
..######..
..#.......
..#####...
..#.......
..######..
..######..
..#.......
..#####...
..#.......
..######..
..#...#...
..#..#....
..##......
..#..#....
..#...#...
Explanation:
- name = "GEEK" input word.
- for ch in name: iterate letters.
- if ch == "G": print(...) directly print the block for each matched case.