Created
March 8, 2021 22:13
-
-
Save MagnetonBora/f5aec97a311de7fd59bfbc800ceb883b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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