...

/

Solution Review: Pascal's Triangle

Solution Review: Pascal's Triangle

This review provides a detailed analysis of the solution to the Pascal's Triangle problem.

We'll cover the following...

Solution: Using Recursion

Press + to interact
def printPascal(testVariable) :
# Base Case
if testVariable == 0 :
return [1]
else :
line = [1]
# Recursive Case
previousLine = printPascal(testVariable - 1)
for i in range(len(previousLine) - 1):
line.append(previousLine[i] + previousLine[i + 1])
line += [1]
return line
# Driver Code
testVariable = 5
print(printPascal(testVariable))

Explanation:

In the code snippet above, we use the values of the previous function call to calculate the values of the current function call. If we reach the 0th0th ...