Skip to content

Instantly share code, notes, and snippets.

@MagnetonBora
Created March 8, 2021 22:13
Show Gist options
  • Save MagnetonBora/f5aec97a311de7fd59bfbc800ceb883b to your computer and use it in GitHub Desktop.
Save MagnetonBora/f5aec97a311de7fd59bfbc800ceb883b to your computer and use it in GitHub Desktop.
def pyramid(n: int) -> list:
size = 2 * n - 1
table = [size * [0] for _ in range(size)]
for start in range(n):
for j in range(size - start):
table[start][start + j] = start + 1
for j in range(size - start):
table[size - 1][start + j] = start + 1
for i in range(size - start):
table[start + i][start] = start + 1
for i in range(size - start):
table[start + i][size - 1] = start + 1
size -= 1
return table
if __name__ == "__main__":
size = int(input("size = "))
for row in pyramid(n=size):
for element in row:
print(element, end=" ")
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment