You are viewing our Forum Archives. To view or take place in current topics click here.
Python Highscore textfile
Posted:

Python Highscore textfilePosted:

Helix-Nebula
  • Christmas!
Status: Offline
Joined: Sep 04, 201013Year Member
Posts: 706
Reputation Power: 29
Status: Offline
Joined: Sep 04, 201013Year Member
Posts: 706
Reputation Power: 29
I attempting to make a high score for text file that only displays the top 5 highscores. I am fairly new to programing and I am not sure how to go about this. This is my section for a group project. I have 5 entires in a text file such as this \
aaa aaa aaa, 1000
aaa, bbb ,bbb 1000
etc
def display_highscore():
    highscorefile = open('highscores.txt', 'r')
    scores = highscorefile.read()
    highscorefile.close()

    score_name = []
    for count in scores.split('\n'):
        info, score = line.split(', ')
        score = int(score)
        score_name.append((info, score))

    for score, name in sorted(score_name):
        print([], name, score)
    return score_name



def add_highscore(user, listofScores):
    highscorefile = open('highscores.txt', 'a')
    for count in range(5):
        if user[3] > score_name[count-1][3]:
            pos = count

    score_name.insert(pos, user)
    for count in range(5):
        print(score_name[count])
    highscorefile.write(score_name)
    highscorefile.close()


user = ["Cat Dog World", 2131232]   
listofScores = display_highscore()
add_highscore(user, listofScores)
#2. Posted:
Xaldin
  • TTG Addict
Status: Offline
Joined: Oct 09, 201013Year Member
Posts: 2,358
Reputation Power: 106
Status: Offline
Joined: Oct 09, 201013Year Member
Posts: 2,358
Reputation Power: 106
Im confused about whats in the text file
#3. Posted:
Terrowin
  • Junior Member
Status: Offline
Joined: Apr 05, 20168Year Member
Posts: 63
Reputation Power: 2
Status: Offline
Joined: Apr 05, 20168Year Member
Posts: 63
Reputation Power: 2
Xaldin wrote Im confused about whats in the text file


If you're referring to the [code] tag within the post, that'd be the code that the OP is asking about... click the double down-facing arrows to expand it and read the entire file.

Unfortunately I'm not familiar enough with Python to have built a high score system. I've only ever really used Python to script events, which even then was translation as opposed to creation. Based on a quick google search, [ Register or Signin to view external links. ] seems to be fairly helpful. The top answer isn't what I referenced, scroll down to the bottom half of the page to view the post about Shelving and Pickling information.
#4. Posted:
Xaldin
  • TTG Addict
Status: Offline
Joined: Oct 09, 201013Year Member
Posts: 2,358
Reputation Power: 106
Status: Offline
Joined: Oct 09, 201013Year Member
Posts: 2,358
Reputation Power: 106
Terrowin wrote
Xaldin wrote Im confused about whats in the text file


If you're referring to the [code] tag within the post, that'd be the code that the OP is asking about... click the double down-facing arrows to expand it and read the entire file.

Unfortunately I'm not familiar enough with Python to have built a high score system. I've only ever really used Python to script events, which even then was translation as opposed to creation. Based on a quick google search, [ Register or Signin to view external links. ] seems to be fairly helpful. The top answer isn't what I referenced, scroll down to the bottom half of the page to view the post about Shelving and Pickling information.

im referencing the "text file" that he is reading from, im aware of how to read the code.
#5. Posted:
Terrowin
  • Junior Member
Status: Offline
Joined: Apr 05, 20168Year Member
Posts: 63
Reputation Power: 2
Status: Offline
Joined: Apr 05, 20168Year Member
Posts: 63
Reputation Power: 2
Xaldin wrote
Terrowin wrote
Xaldin wrote Im confused about whats in the text file


If you're referring to the [code] tag within the post, that'd be the code that the OP is asking about... click the double down-facing arrows to expand it and read the entire file.

Unfortunately I'm not familiar enough with Python to have built a high score system. I've only ever really used Python to script events, which even then was translation as opposed to creation. Based on a quick google search, [ Register or Signin to view external links. ] seems to be fairly helpful. The top answer isn't what I referenced, scroll down to the bottom half of the page to view the post about Shelving and Pickling information.

im referencing the "text file" that he is reading from, im aware of how to read the code.


I assume the text file would contain the high scores that have been saved, but I can't be certain without the OP coming back to thread.
#6. Posted:
Helix-Nebula
  • 2 Million
Status: Offline
Joined: Sep 04, 201013Year Member
Posts: 706
Reputation Power: 29
Status: Offline
Joined: Sep 04, 201013Year Member
Posts: 706
Reputation Power: 29
Sorry guys about that. My group member figured it out by using a lot of for loops and list. The highscore fille was suppose to contain first name last name country, score
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.