Question
[[ PYTHON ]] Write a program to create Pascal's triangle (but with a twist!). The first five rows are shown below. On row 0, write
[[ PYTHON ]] Write a program to create Pascal's triangle (but with a twist!). The first five rows are shown below.
On row 0, write only the number 1. Then, for the next row, add the number directly above and to the left with the number directly above and to the right to find the new value. If the number to the right or left is not present, substitute a 0 in its place. For example, the first number in row 1 is 0 + 1 = 1, whereas the numbers 1 and 3 in row 3 are added to give the number 4 in row 4.
Hint: Use a list for each row, and use a list of lists to hold the whole triangle. The position of each number in the triangle can be translated to indices in the lists. Keep placeholders in the list to represent "empty" cells in each row. Only every second entry would actually contain a number. This makes it easy to find the left and right parent of each cell. The output of each line must be centered.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started