By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,983 Members | 2,035 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,983 IT Pros & Developers. It's quick & easy.

how to limit top 5 high scores

P: 2
Expand|Select|Wrap|Line Numbers
  1. import pickle
  2.  
  3. scores = open("scores", "r")
  4. # READ the pickled data then add to it.
  5. hiscores = pickle.load(scores)
  6. scores.close()
  7. print hiscores
  8.  
  9. # Use int() to get a number from raw_input()
  10. score=int(raw_input("Score?"))
  11.  
  12. player=raw_input("Name?")
  13. hiscores.append((score, player))
  14. print hiscores
  15.  
  16. hiscores.sort()
  17. print hiscores
  18.  
  19. scores=open("scores", "w")
  20. pickle.dump(hiscores[-10:], scores)
  21. scores.close()
  22.  
  23. scores = open("scores", "r")
  24. oldscores = pickle.load(scores)
  25. scores.close()
  26. #print oldscores
  27.  
  28. print
  29.  
  30. print oldscores
May 8 '14 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
I don't understand your question. You are already saving the top 10 scores.
May 8 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.