I am trying to write a function that prints out a input file: "table.txt" as seen on the left:
into the format as seen to the right of the image.
I have tried:
f = open("table1.txt",'r')
for aline in f:
values = aline.split(',')
print('Team:',values[0],', Points:',values[1],', Diff:',int(values[2])-int(values[3]),'Goals:',values[2])
f.close()
Which outputs:
Team: FC Ingolstadt 04 , Points: 13 , Diff: -2 Goals: 4
Team: Hamburg , Points: 9 , Diff: -2 Goals: 8
Team: SV Darmstadt 98 , Points: 9 , Diff: -1 Goals: 8
Team: Mainz , Points: 9 , Diff: -3 Goals: 6
Team: FC Augsburg , Points: 4 , Diff: -5 Goals: 7
Team: Werder Bremen , Points: 6 , Diff: -5 Goals: 7
Team: Borussia Moenchengladbach , Points: 6 , Diff: -6 Goals: 9
Team: Hoffenheim , Points: 5 , Diff: -4 Goals: 8
Team: VfB Stuttgart , Points: 4 , Diff: -8 Goals: 9
Team: Schalke 04 , Points: 16 , Diff: 11 Goals: 14
Team: Hannover 96 , Points: 2 , Diff: -12 Goals: 6
Team: Borrusia Dortmund , Points: 16 , Diff: 11 Goals: 15
Team: Bayern Munich , Points: 18 , Diff: 16 Goals: 18
Team: Bayer Leverkusen , Points: 14 , Diff: 3 Goals: 11
Team: Eintracht Frankfurt , Points: 9 , Diff: 4 Goals: 13
Team: Hertha BSC Berlin , Points: 14 , Diff: 1 Goals: 5
Team: 1. FC Cologne , Points: 13 , Diff: 0 Goals: 10
Team: VfB Wolfsburg , Points: 14 , Diff: 4 Goals: 10
But how do you print the values so that the rows are numbered and the columns have the titles: "Team, Points, Diff, Goals"?