For I in range (10) :
A.a ppend ([])
For j in range (I + 1) :
A [I]. Append ([1] if j==0 or j==I else [])
For I in a:
Print (I)
For I in range (2, 10) :
For j in range (1, I) :
A [I] [j]=sum (a [I - 1] [1], [I - 1] [j])
For I in a:
Print (I)
Python version 3.6, the printing Yang hui triangle,
Run prompt list indices beyond, but I don't see why beyond, help
CodePudding user response:
A=[]For I in range (10) :
A.a ppend ([])
For j in range (I + 1) :
A [I]. Append ([1] if j==0 or j==I else [])
For I in a:
Print (I)
For I in range (2, 10) :
For j in range (1, I) :
A [I] [j]=sum (a [I - 1] [1], a [j] [I - 1])
For I in a:
Print (I)
Sticky when accidentally deleted an a,
CodePudding user response:
A=[]For I in range (10) :
A.a ppend ([])
For j in range (I + 1) :
A [I]. Append (1 if j==0 or j==I else 0)
For I in a:
Print (I)
For I in range (2, 10) :
For j in range (1, I) :
A [I] [j]=[I - 1] a [j - 1) + a (I - 1) [j]
For I in a:
Print (I)
CodePudding user response:
def res (n) :
If n & lt; 3: the return of [1] * n
S=res (n - 1)
Return [1] + [s + s [_] [_ + 1] for _ in range (n - 2)] + [1]
For _ in range (1, 11) :
Print (res) (_)