Python 编写函数,接收一个整数t为参数,打印杨辉三角前t行。
编写函数,接收一个整数t为参数,打印杨辉三角前t行。#编写函数,接收一个整数t为参数,打印杨辉三角前t行。def yanghui(t):print([1])line = [1,1]print(line)for i in range(2,t):r = []for j in range(0,len(line) - 1):r.append(line[j]+line[j+1])line = [
·
编写函数,接收一个整数t为参数,打印杨辉三角前t行。
#编写函数,接收一个整数t为参数,打印杨辉三角前t行。
def yanghui(t):
print([1])
line = [1,1]
print(line)
for i in range(2,t):
r = []
for j in range(0,len(line) - 1):
r.append(line[j]+line[j+1])
line = [1]+r+[1]
print(line)
更多推荐
已为社区贡献2条内容
所有评论(0)