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).
Output
The output should be (2*N - 1) rows and (2*N - 1) columns containing the alphabet characters in the hollow diamond pattern.Explanation
For example, if the given number is 5, the pattern should contain 9 rows and 9 columns as shown below.
# array of letters
L=['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']
# input value from a user
n=int(input('Input N>'))
print('N='+str(n))
# print lines from 1 to N
for i in range(n):
s=''
for j in range(n-1-i):
s=s+' '
s=s+L[i%26]
for j in range(i-1):
s=s+' '
if i>0:
s=s+' '+L[i%26]
print(s)
# print lines from N+1 to 2*N-1
for i in reversed(range(n-1)):
s=''
for j in range(n-1-i):
s=s+' '
s=s+L[i%26]
for j in range(i-1):
s=s+' '
if i>0:
s=s+' '+L[i%26]
print(s)
Comments
Leave a comment