2 回答
TA贡献1776条经验 获得超12个赞
下面的输出不是你期望的吗?
In [1]: n = 5
In [2]: for i in range(n):
...:
...: num = 1
...:
...: for j in range(i + 1):
...: print(num, end=" ")
...: num = num + 1
...:
...: print("\r")
...:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
编辑:如果 n=1 不在内部循环中,则反事实输出。
In [1]: n = 5
In [2]: num = 1
In [3]: for i in range(n):
...: for j in range(i + 1):
...: print(num, end=" ")
...: num = num + 1
...: print("\r")
...:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
添加回答
举报