Day13: given an integer n, n lines obtained before Pascal's Triangle
. 1 DEF numRows (n): 2 S1 = [] # Pascal's triangle before store n row number . 3 for I in Range (. 1, n +. 1 ): . 4 S = [. 1 for J in Range (I)] # storage section the number i is set to the first row. 1 . 5 IF len (S)> 2 : . 6 for i in Range (. 1, len (S) -1 ): . 7 S [i] = S1 [-1] [. 1-i] S1 + [-1 ] [I] . 8 s1.append (S) . 9 the else : 10 s1.append (S) . 11 return s1 12 13 print(numrows(6))
Output: