Python Practice › Loop Programs › Program 90

Lowercase letter diamond

MediumLoop Programs · 90 of 90

Write a Python program to print the letters a to y in rows of 1, 3, 5, 7, 5, 3, 1 letters.

Advertisement
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

  1. Same idea as the previous program with different row sizes.

Solution

Python
import string letters = iter(string.ascii_lowercase)for size in [1, 3, 5, 7, 5, 3, 1]:    print(" ".join(next(letters) for _ in range(size)))
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

Line by line

Line 3

An iterator hands out the letters one at a time across all rows.

Line 5

next(letters) takes the following letter each time it is called.

Learn the concept

New to this topic? Read the lesson, then come back.

More loop programs

← All 90 Loop Programs

Leave a Comment