(loop)
• Row 0 contains 1 number—the number 1
• Each subsequent row is one longer than the one before and follows the pattern that you’ll discover.
The first five rows are
[[1],
[1, 2],
[2, 3, 5],
[5, 7, 10, 15],
[15, 20, 27, 37, 52]
]
Your task: Implement a function LoTri(n: int) -> List[List[int]]
1
Expert's answer
2020-06-25T08:00:55-0400
def LoTri(n):
answer = [[1]]
for i in range(1, n):
answer.append([answer[i - 1][-1]])
for j in range(1, i + 1):
answer[i].append(answer[i-1][j-1] + answer[i][j-1])
return answer
n = int(input('Set n: '))
print(LoTri(n))
Comments
Leave a comment