gpt4 book ai didi

Python-3.x:如何在相等的列中打印多个列表?

转载 作者:行者123 更新时间:2023-12-01 08:36:56 26 4
gpt4 key购买 nike

我对 python 很陌生,我正在尝试输出多个列表,一个在另一个下,在列中,但我不知道。

我当前的输出是:

Name, Count, Correct, Incorrect, Accuracy, Total

Abena 3 3 0 100 45

Malcolm 1 1 0 100 1

Jane 1 1 0 100 20

Liz 1 1 0 100 10

Andy 1 0 1 0 20

Sandip 0 0 0 0 0

如何将数字分成单独的列?

当前要打印的代码是:

CoinFile = open("CoinCount.txt", "r")
print("Name, Count, Correct, Incorrect, Accuracy, Total")
for record in VolunteersToSort:
print(record[0] + " " + record[1]+ " " + record[2] + " " + record[3] + " " + record[4] + " " + record[5] )

文件内容:

['Abena', '3', '3', '0', '100', '45']
['Malcolm', '1', '1', '0', '100', '1']
['Jane', '1', '1', '0', '100', '20']
['Andy', '1', '0', '1', '0', '20']
['Sandip', '0', '0', '0', '0', '0']
['Liz', '1', '1', '0', '100', '10']

最佳答案

header = ['Name', 'Count', 'Correct', 'Incorrect', 'Accuracy', 'Total']
my_list = [
['Abena', '3', '3', '0', '100', '45'],
['Malcolm', '1', '1', '0', '100', '1'],
['Jane', '1', '1', '0', '100', '20'],
['Andy', '1', '0', '1', '0', '20'],
['Sandip', '0', '0', '0', '0', '0'],
['Liz', '1', '1', '0', '100', '10']
]
print("{: >10} {: >10} {: >10} {: >10} {: >10} {: >10}".format(*header))
for row in my_list:
print("{: >10} {: >10} {: >10} {: >10} {: >10} {: >10}".format(*row))

您的输出将为:

      Name      Count    Correct  Incorrect   Accuracy      Total 
Abena 3 3 0 100 45
Malcolm 1 1 0 100 1
Jane 1 1 0 100 20
Andy 1 0 1 0 20
Sandip 0 0 0 0 0
Liz 1 1 0 100 10

您可以根据需要编辑列长度。这里使用 10。

关于Python-3.x:如何在相等的列中打印多个列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53670132/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com