码迷,mamicode.com
首页 > 编程语言 > 详细

用python实现杨辉三角

时间:2019-06-25 15:10:35      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:print   while   python实现   python   div   int   杨辉三角   pre   实现   

def yanghui(lines):
       currentlst,lastlst,n=[],[],1
       if lines<1:
              return
       while n<=lines:
              lastlst=currentlst
              currentlst=[]
              for i in range(n):
                     if(i==0):
                            currentlst.insert(0,1)
                     elif(i==n-1):
                            currentlst.insert(i,1)
                     else:
                            currentlst.insert(i,lastlst[i]+lastlst[i-1])
              n=n+1
              yield currentlst
              
f = yanghui(10)
for t in f:
       print(t)

  

用python实现杨辉三角

标签:print   while   python实现   python   div   int   杨辉三角   pre   实现   

原文地址:https://www.cnblogs.com/quota/p/11082545.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!