Python exercises - output method list of Pascal's Triangle

DEF main (): 
    num = int (the INPUT ( ' Please enter the number of lines: ' )) 
    yh = [[]] * num     # Create a num lines empty list 
    for Row in the Range (len (yh)):   # through each row 
        yh [row] = [None] * (row + 1 )
         for COL in Range (len (YH [row])): # through each column 
            IF COL == 0 or COL == row:   # if the number of columns is 1 or ranks enabling the number of elements are equal. 1 
                YH [Row] [COL]. 1 = the else : 
                YH [Row] [COL] = YH [Row -. 1] [COL] + YH [Row -. 1] [COL -. 1]   #
            The current value of the line elements and column elements of the same elements of the former and 
            Print (YH [Row] [COL], End = ' \ T ' )
         Print () 

main ()

Results are as follows

 

Guess you like

Origin www.cnblogs.com/hyz1900457346/p/11917665.html