Discuss / Python / 杨辉三角作业的实现

杨辉三角作业的实现

Topic source

sofa_th

#1 Created at ... [Delete] [Delete and Lock User]
def triangles(n):
	L=[]
	if n==1:
		L.append(1)
	if n==2:
		L.append(1)
		L.append(1)	
	if n>2:
		L.append(1)
		L.append(1)
		LUP=triangles(n-1)
		for i in range(1,n-1):
			L.insert(i,LUP[i-1]+LUP[i])
	return L
print(triangles(4))

def yang(n):
	y=[]
	for i in range(n):
		y.append(triangles(i+1))
	return y
yy=yang(10)	
for i in range(10):
	print(yy[i])

sofa_th

#2 Created at ... [Delete] [Delete and Lock User]

怎么删除评论?好像把结果放错位置


  • 1

Reply