Hollow Inverted Half Pyramid - 2
Given the number of rows N, write a program to print the hallow inverted half pyramid pattern similar to the pattern shown below.
1 2 3 4 5
1 4
1 3
1 2
1
Input
The input will be a single line containing a positive integer (N).
Output
The output should be N rows containing the numbers in the hollow inverted half pyramid pattern.
Note: There is a space after each number.
N = int(input())
length = N * 2 - 1
pattern = [' '.join([str(x) for x in range(1, N + 1)])]
for i in range(1, N - 1):
center_width = length - 2 * i - 2
pattern.append('{0}{1}{2}'.format('1', ' ' * center_width, str(N - 1)).rjust(length , ' '))
N -= 1
pattern.append('1'.rjust(length , ' '))
for i in pattern:
print(i)
Comments
Leave a comment