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

35 lines
723 B
Python

try:
from common.inputChecking.typeCheck import inputTypeCheck
except ModuleNotFoundError:
print('Sjekk README.md for hvilke flagg python trenger')
exit(1)
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 = inputTypeCheck('n: ', int)
print(solutionWithForLoops(n))