myfile = open('Results.txt')
title = '{0:20} {1:20} {2:20} {3:20} {4:20}'.format('Player Nickname','Matches Played','Matches Won','Matches Lost','Points')
print(title)
for line in myfile:
item = line.split(',')
points = int(item[2]) * 3
if points != 0:
result = '{0:20} {1:20} {2:20} {3:20} {4:20}'.format(item[0], item[1], item[2], item[3],points)
print(result)
嗨,那裏只是需要一些幫助,那些知道如何正確使用.format,出於某種原因,當打印答案時。我會期待這一點。代碼不以正確的格式打印
Player Nickname Matches Played Matches Won Matches Lost Points
Leeroy 19 7 12 21
但顯示的輸出我得到的是這種
Player Nickname Matches Played Matches Won Matches Lost Points
Leeroy 19 7 12
21
21被顯示在錯誤的地方。我做錯了什麼?
沒有我寫了出來 繼承人的輸出 '玩家暱稱比賽場次比賽贏得比賽失分 Leeroy 19 7 12 21' –