Given the number of rows N, write a program to print the hallow diamond pattern similar to the pattern shown below.
A
B B
C C
D D
E E
D D
C C
B B
A
The input will be a single line containing a positive integer (N).
alphabetList=['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', 'Z']
diamond =[]
#get the number of rows from the user
rows=-1
while rows<1 or rows>26:
rows=int(input("Enter the number of rows N: "))
for i in range(0, rows):
#add letters
diamond.append("")
for j in range(0, rows-i):
diamond[i] += " "
diamond[i] += alphabetList[i];
if alphabetList[i] != 'A':
#add spaces between letters
for j in range(0, 2 * i - 1):
diamond[i] += " "
diamond[i] += alphabetList[i]
#print the first part of the diamond
print(diamond[i])
#print the second part of the diamond
for i in reversed(range(0,rows-1)):
print(diamond[i])
Example
Enter the number of rows N: 10
A
B B
C C
D D
E E
F F
G G
H H
I I
J J
I I
H H
G G
F F
E E
D D
C C
B B
A
Comments
Leave a comment