First 5 rows
Input
pascals_triangle(5)
Output
[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]
Each row is built from the previous row by summing adjacent pairs and adding 1s at the ends.
Full lesson preview
Produce the first n rows of Pascal's triangle using loops.
Problem statement
Task
Examples
Input
pascals_triangle(5)
Output
[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]
Each row is built from the previous row by summing adjacent pairs and adding 1s at the ends.
Input format
Output format
Constraints
Samples
Input
pascals_triangle(3)
Output
[[1], [1, 1], [1, 2, 1]]
Three rows starting from [1].