无法使用 for 循环
Not Able To use for-loop
** 我想使用两个 for-loops 而不是两个 while-loops **
i = 7
while i >= 1:
j = i
while j <= 7:
print(j, end =" ")
J += 1
i -= 1
print()
以下是 for-loop
等价物:
for i in range(7, 0, -1):
j = i
for j in range(i, 8):
print(j, end=" ")
print()
关键是正确使用range(start, stop, step)
. See also this。
** 我想使用两个 for-loops 而不是两个 while-loops **
i = 7
while i >= 1:
j = i
while j <= 7:
print(j, end =" ")
J += 1
i -= 1
print()
以下是 for-loop
等价物:
for i in range(7, 0, -1):
j = i
for j in range(i, 8):
print(j, end=" ")
print()
关键是正确使用range(start, stop, step)
. See also this。