0

This is how the output should look like in the text file

Ray Holt
5 5 0 0 100 15
Jessica Jones
12 0 6 6 50 6
Johnny Rose
6 2 0 4 20 10
Gina Linetti
7 4 0 3 300 15

The number is the result from the game that I have to create.

My question is, how can I write to the text file with both string and integer result ? I have tried this

def write_to_file(filename, player_list):
    output = open(filename, "w")    
    for player in player_list:
        output.write(str(player))

but the output is

Ray Holt                   5  5  0  0     100      15Jessica Jones             12  0  6  6      50      6Johnny Rose                6  2  0  4      20      10Gina Linetti               7  4  0  3     300      15Khang                      0  0  0  0     100       0

They are in 1 line

Please help me! Thanks a lot guys

1 Answers1

1

Use this:

def write_to_file(filename, player_list):
    output = open(filename, "w")    
    for player in player_list:
        output.write(str(player)+'\n')
output.close()
Sid
  • 2,174
  • 1
  • 13
  • 29
  • It doesnt work as I expect. The output should be a name line and then the number line then the name line and number line and so on – Khang Nguyen Nov 02 '19 at 09:40
  • 1
    @KhangNguyen I don't know how player_list looks like. As such, I can't get a sample output. Please show at least some part of the list. – Sid Nov 02 '19 at 10:18