29 lines
551 B
Python
29 lines
551 B
Python
def numberPyramid(length):
|
|
for i in range(length):
|
|
row = ''
|
|
for k in range(i + 1):
|
|
row += f'{k+1} '
|
|
print(row)
|
|
|
|
|
|
def numberPyramidGenerator():
|
|
currentList = ['1']
|
|
while True:
|
|
yield ' '.join(currentList)
|
|
currentList.append(str(int(currentList[-1]) + 1))
|
|
|
|
|
|
def solutionWithForLoops(n):
|
|
return numberPyramid(n)
|
|
|
|
|
|
def solutionWithGenerator(n):
|
|
myGenerator = numberPyramidGenerator()
|
|
for i in range(n):
|
|
print(next(myGenerator))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
n = int(input('n: '))
|
|
print(solutionWithForLoops(n))
|