用python实现杨辉三角


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)

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM