Fun Python Programming (C) Pascal's Triangle (original)

Original link: http://www.cnblogs.com/maodouzi/archive/2011/07/12/2104153.html

Pascal's Triangle, is estimated in the domestic over-Mathematical Olympiad classes of children have learned.

About introduction of Pascal's Triangle, you can see Baidu Encyclopedia: http: //baike.baidu.com/view/7804.htm

Here are implementations of Python, mainly to see the wording of the C language, Jijiwaiwai, Jijiwaiwai, really can not endure, he wrote a hands-:

 
   
1 NUM = 5
2
3   def printLine(lineList):
4 lineList = [str(tmpNum) for tmpNum in lineList]
5 print ( " %s%s " % ( " " * (NUM - len(lineList)), " " .join(lineList)))
6
7   for i in range(NUM):
8 if i < 2 :
9 yhList = [ 1 ] * (i + 1 )
10 else :
11 yhList[ 1 : - 1 ] = [(tmpNum + yhList[j]) for j, tmpNum in enumerate(yhList[ 1 :])]
12 printLine(yhList)

Results are as follows:

 
   
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

I always feel that there are still places in the code streamlined, write fewer lines.

Left to come back after optimization, huh, huh.

Daren hope Python wing.

Reproduced in: https: //www.cnblogs.com/maodouzi/archive/2011/07/12/2104153.html

Guess you like

Origin blog.csdn.net/weixin_30194507/article/details/94796314