Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    0
    ReputationRep:
    I have to store the scores of people in a text file as an array, and I should be able to add each record on the array. This is the part of the code where the scores are being stored:

    Name:  image.jpeg
Views: 53
Size:  93.1 KB
    However, when I add a new score, it gets added on the same line, and if the name is the same, a new record with the new name is created for example:John, 5,John, 3,Sam, 2, instead of:
    John, 5, 3
    Sam, 2
    What can I do to fix this?
    • PS Reviewer
    Offline

    16
    ReputationRep:
    PS Reviewer
    (Original post by Sibghy)
    I have to store the scores of people in a text file as an array, and I should be able to add each record on the array. This is the part of the code where the scores are being stored:

    Name:  image.jpeg
Views: 53
Size:  93.1 KB
    However, when I add a new score, it gets added on the same line, and if the name is the same, a new record with the new name is created for example:John, 5,John, 3,Sam, 2, instead of:
    John, 5, 3
    Sam, 2
    What can I do to fix this?
    You need to write a newline character after you make an entry. To avoid duplicate names, you first need to check for the name you are adding, then update it rather than just appending the new entry at the end.
    • Thread Starter
    Offline

    0
    ReputationRep:
    (Original post by Jooooshy)
    You need to write a newline character after you make an entry. To avoid duplicate names, you first need to check for the name you are adding, then update it rather than just appending the new entry at the end.
    So would it be:
    ...name, score\n))
    ?
    Offline

    3
    ReputationRep:
    (Original post by Sibghy)
    So would it be:
    ...name, score\n))
    ?
    Put it inside your string.
    Code:
    "{}:{}\n".format(name, score)
    • Thread Starter
    Offline

    0
    ReputationRep:
    (Original post by Push_More_Button)
    Put it inside your string.
    Code:
    "{}:{}\n".format(name, score)
    Thanks
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Would you like to hibernate through the winter months?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.