我是一个python初学者,帮我看看

img


打印如图输出样子

1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
这样的输出形式

https://www.liaoxuefeng.com/wiki/1016959663602400

题目是不是第二行的 1 1 漏了呀

如果有把下面第7行去掉即可

def yh(n):
    if n==1:return [1]
    t = yh(n-1)
    return list(map(sum,zip([0]+t,t+[0])))

for i in range(1,7):
    if i!=2:
        print(*yh(i))

n=6
list1=[]
for n in range(n):
row=[1]
list1.append(row)
if n==0:
continue
for m in range(1,n):
row.append(list1[n-1][m-1]+list1[n-1][m])
row.append(1)

del list1[1]

for i in list1:
for j in i:
print(j, end=" ")
print()

def test(list = [1], XHCS = 10):
"""
传入一个列表,
"""
print(1)
xhcs_log = 0
while(xhcs_log < XHCS):
xhcs_log += 1
list_Return = []
if len(list) == 1:
list_Return.append(list[0])
list_Return.append(list[0]+ list[0])
list_Return.append(list[0])
else:
list_Return.append(list[0])
for num, list_data in enumerate(list):
if num == 0:
continue
else:
list_Return.append(list[num] + list[num-1])
list_Return.append(list[0])

    for data in list_Return:
        print(data,end= " ")
    list = list_Return
    print("")

if name == "main":
test()

img

img

他们都太复杂了,看我的。
a="""
1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
"""
print(a)