Discuss / Python / 抄的,还是不懂

抄的,还是不懂

Topic source
1 #!/usr/bin/env python3
  2 def triangles(num):
  3     b=[1]
  4     n=0
  5     a=[]
  6     while n<num:
  7         yield b
  8         for i in range(1,len(b)):
  9             a.append(b[i]+b[i-1])
 10         b=[1]+a+[1]
 11         a=[]
 12         n=n+1
 13 num=input('Please input number: ')
 14 num=int(num)
 15 for n in triangles(num):
 16     print(n)

  • 1

Reply