tags:

views:

107

answers:

2

Hi, I am looking for a Pascals triangle using python script

I have done till here and have no idea how to add on

numstr= raw_input("please enter the height:")
height = int( )

tri = []

row1 = [1]
row2 = [1, 1]
tri.append(row1)
tri.append(row2)

while len(tri) < height:
+2  A: 

You would have to take the last row there is in the triangle and create the next one like this:

  1. Put a 1 at the start of the new row
  2. For every number in the last row except the last, calculate the sum of the number and its right neighbor and put it into the new row
  3. Put another 1 at the end of the new row

You could also calculate the new numbers using binomial coefficients, though that's likely a little more work to get right.

Joey