TDT4109/Exercise 3/11 - Doble lokker/task11a.py

31 lines
586 B
Python
Raw Normal View History

2020-09-15 09:27:47 +02:00
from common import inputTypeCheck
2020-09-14 14:34:03 +02:00
def numberPyramid(length):
for i in range(length):
row = ''
2020-09-14 16:36:09 +02:00
for k in range(i + 1):
2020-09-14 14:34:03 +02:00
row += f'{k+1} '
print(row)
2020-09-14 16:36:09 +02:00
2020-09-14 14:34:03 +02:00
def numberPyramidGenerator():
currentList = ['1']
while True:
yield ' '.join(currentList)
currentList.append(str(int(currentList[-1]) + 1))
def solutionWithForLoops(n):
return numberPyramid(n)
2020-09-14 16:36:09 +02:00
2020-09-14 14:34:03 +02:00
def solutionWithGenerator(n):
myGenerator = numberPyramidGenerator()
for i in range(n):
print(next(myGenerator))
2020-09-14 16:36:09 +02:00
2020-09-14 14:34:03 +02:00
if __name__ == "__main__":
2020-09-14 16:36:09 +02:00
n = int(input('n: '))
print(solutionWithForLoops(n))