Answer to Question #123815 in Python for Desimio Papatakorn

Question #123815
(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))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS