Advertisement
go6odn28

03. Magic Triangle

Jun 1st, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. def get_magic_triangle(rows):
  2.     triangle = [[1], [1, 1]]
  3.  
  4.     for row in range(2, rows):
  5.         current_row = []
  6.         current_row.append(1)
  7.         for col in range(row-1):
  8.             current_row.append(triangle[-1][col] + triangle[-1][col+1])
  9.         current_row.append(1)
  10.         triangle.append(current_row)
  11.     return triangle
  12.  
  13.  
  14. print(get_magic_triangle(5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement