Haj*_*dic 2 python loops for-loop rows while-loop
我正在学习使用python而且我坚持使用这段代码.
我想显示行,但我得到列.我尝试了不同的变化,我为while循环得到一行,但我仍然得到for循环的列.
Start_num = 0
Max_num = 200
while Start_num < 201:
for Number in range (Max_num, -1, -25):
print(Start_num, end=' ')
Start_num += 25
print(Number)
Run Code Online (Sandbox Code Playgroud)
这是输出当前查找此代码的方式.
0 200
25 175
50 150
75 125
100 100
125 75
150 50
175 25
200 0
Run Code Online (Sandbox Code Playgroud)
必须有一种方法来获得两行而不是列,请帮忙.
试试这个:
Start_num = 0
Max_num = 200
row1 = []
row2 = []
while Start_num < 201:
for Number in range (Max_num, -1, -25):
row1.append(str(Start_num))
Start_num += 25
row2.append(str(Number))
print(" ".join(row1))
print(" ".join(row2))
Run Code Online (Sandbox Code Playgroud)
您需要提前构建行,然后在最后打印它们.终端仅以文本形式输出,没有行或列的概念.