Challenge 2: Pascal's Triangle

Given a number return a list containing the values of the Pascal's Triangle of that size.

Problem Statement

Implement a function that takes a number testVariable and returns that row of the Pascal’s triangle.

What is Pascal’s Triangle?

Pascal’s triangle is a triangular array of the binomial coefficients.

The entry in the nthnth row and kthkth column of Pascal’s triangle is denoted

(nk){\displaystyle {\tbinom {n}{k}}}

For example, the unique nonzero entry in the topmost row is

(00)=1{\displaystyle {\tbinom {0}{0}}=1}

With this notation, any element can be written as:

(nk)=(n1k1)+(n1k){\displaystyle {n \choose k}={n-1 \choose k-1}+{n-1 \choose k}}

PascalTriangleAnimated2.gif
By Hersfold on Wikipedia

Input

A variable testVariable that contains the number of the row that you have to return of the Pascal Triangle.

widget

Output

A list containing the values of the specific row of Pascal Triangle

Sample Input

5

Sample Output

[1, 5, 10, 10, 5, 1]

Try it Yourself

Try to attempt this challenge by yourself before moving on to the solution. Good luck!

Press + to interact
def printPascal(testVariable) :
# Write your code here
return None

Let’s have a look at the solution review of this problem.