请在下面横线填写正确的代码 蛇形矩阵是由1开始的自然数依次排列成的一个矩阵上三角形。 例如,当输入5时,应该输出的三角形为: 1 36 10 15 2 5 9 14 4 8 13 7 12 11 编程代码: while 1: try: n = int(input0) list1 = [ for i in range(1,n+1) list1.append([0]*i) a =0 for i in range(n): for jin range(i+1): a=a+1 list1[0]0]=a list2,she=1.0 for i in range(1,n+1): for line in list1: if line: list2.append(__请在下面输入框补充代码__) she.append(" \".join(map(str,list2))) list2 = 1 for i in she: print(1) except: break 示例: 输入 :4 输出:136 10
时间: 2023-02-12 20:44:17 浏览: 153
使用for语句在屏幕上画一个五角星_happyxt3_使用for语句在屏幕上画一个五角星_
while 1:
try:
n = int(input())
list1 = [[0]*i for i in range(1,n+1)]
a = 1
for i in range(n):
for j in range(i+1):
list1[i][j] = a
a += 1
list2 = []
she = []
for i in range(1,n+1):
for line in list1:
if line[:i]:
list2.append(line[:i])
she.append(" ".join(map(str,list2)))
list2 = []
for i in she:
print(i)
except:
break
阅读全文