Python Practice › Loop Programs › Program 89
Uppercase letter diamond
Write a Python program to print the letters A to Y in rows of 1, 2, 3, 4, 5, 4, 3, 2, 1 letters.
Output
A B C D E F G H I J K L M N O P Q R S T U V W X Y
Approach
- Keep a letter counter and print the right number of letters on each row.
Solution
sizes = [1, 2, 3, 4, 5, 4, 3, 2, 1]code = ord("A")for size in sizes: row = [chr(code + i) for i in range(size)] print(" ".join(row)) code += sizeOutput
A B C D E F G H I J K L M N O P Q R S T U V W X Y
Line by line
Line 2
ord("A") is 65; adding to it walks through the alphabet.
Line 4
Each row takes the next size letters.
Learn the concept
New to this topic? Read the lesson, then come back.