473,473 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to limit top 5 high scores

2 New Member
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
1 1922
bvdet
2,851 Recognized Expert Moderator Specialist
I don't understand your question. You are already saving the top 10 scores.
May 8 '14 #2

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

Similar topics

2
by: Phil Powell | last post by:
Relevancy scores are normally defined by a MySQL query on a table that has a fulltext index. The rules for relevancy scoring will exclude certain words due to their being too short (minimum...
0
by: asrock | last post by:
i have prepared a code in c++ to save high scores and it is working well when i compile it in turbo c++and run the code . but when i exit from the turbo c++ , the file to which i saved the high...
2
by: Anthony | last post by:
I have a team website that has several games for entertainment. One of the games is a javascript version of yahtzee. Can someone suggest a way, using javascript, to record a high score for the...
4
by: jocknerd | last post by:
About 10 years ago, I wrote a C app that would read scores from football games and calculate rankings based on the outcome of the games. In fact, I still use this app. You can view my rankings at...
11
by: Israel | last post by:
I've trying to write a query that seems like it should be simple but for some reason my attempts are not working. This is really a general SQL quesion and doesn't pertain to MySQL but I couldn't...
4
by: kyle christian | last post by:
I am trying to save the high scores of a game I made. Now Im stumped on trying to search through the file. Should I use a string, array, or one of the STL containers to manipulate the information...
8
by: toefraz | last post by:
Hi, guys. I'm writing a little game, and I want to include a high scores list. I've got everything coded except for the sorting part. I want to use the std::sort() function, but I'm not quite sure...
8
by: d24706 | last post by:
Hello, I hope someone can help me. I had to do the following assignment( i have most of it done just cant finish it off, question and source code below). Question? Write a Java program that...
3
by: hamishmcgee | last post by:
Ok, so for a project at university I have to create a High Score table in C++ with Visual Studio. Just to let you know this is my first year at university and also my first time ever learning C++....
3
by: serdar | last post by:
Hi, I've built a Flash game and using PHP to save scores to a text file. Everything works fine so far. My potential problem is that I'm not sure what happens when there are multiple requests to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.