Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 有没有更好的方法来制作/展示我的清单?_Python_List_Output_Modulo - Fatal编程技术网

Python 有没有更好的方法来制作/展示我的清单?

Python 有没有更好的方法来制作/展示我的清单?,python,list,output,modulo,Python,List,Output,Modulo,此问题已更新: 我通过引入for循环并只使用一个列表而不是两个列表,成功地让我的程序打印出我想要的内容。像这样: while i <= rows: j = 1 while j <= seats: k = j+(4*(i-1)) field.append("{}".format(k)) #Adds the two values to one. j += 1 i += 1 a = 1 b

此问题已更新:

我通过引入for循环并只使用一个列表而不是两个列表,成功地让我的程序打印出我想要的内容。像这样:

   while i <= rows:
    j = 1
    while j <= seats:
        k = j+(4*(i-1))
        field.append("{}".format(k))  #Adds the two values to one.
        j += 1
    i += 1

a = 1
b = 1
for isle in range(rows):
    for column in range(seats):
        if a == 13:
            print(" ↓ TYST AVD ↓")
        if a % 4 != 0:
            print(field[a-1].ljust(4), end='')
        else:
            print(field[a-1].ljust(4), end=''+"\n")
        a += 1
b += 1
我的问题是让每一行都反转,即我希望:

1   2   3   4   
8   7   6   5   
9   10  11  12  
 ↓ TYST AVD ↓
16  15  14  13  
17  18  19  20  
24  23  22  21

我尝试过用几种不同的方法实现模运算,但似乎无法实现。这可能与模有关,还是我必须重新考虑所有问题?

检查
s
是列表还是字符串。如果是字符串,则正常打印,而不是将其分散到多个参数中

for s in field:
    if isinstance(s, list):
        print(*s)
    else:
        print(s)

堆栈溢出不是为了替换现有的文档和教程。请阅读有关输出格式的教程。查看如何指定字段宽度。
for s in field:
    if isinstance(s, list):
        print(*s)
    else:
        print(s)