简体   繁体   English

如何使用python中的文本文件创建排行榜?

[英]How do I create a Leaderboard using a text file in python?

I'm working on a quiz for my exam in computer science.我正在为我的计算机科学考试做一个测验。 I'm relatively new to the program, in the sense that I know all of the basics, but I am on the point where I want to expand my knowledge.我对这个程序比较陌生,因为我知道所有的基础知识,但我正想扩展我的知识。 One way I want to do this is by adding a Leaderboard system.我想要做到这一点的一种方法是添加排行榜系统。 The user gets a number of points, and then the program checks in a text file that has other high scores in it, and adds the user to it.用户获得一定数量的分数,然后程序签入一个包含其他高分的文本文件,并将用户添加到其中。 It then prints out the leaderboard.然后它打印出排行榜。 This means that I'm going to have to use some sort of operations to determine whether the user's score is higher or lower than another score in the file, and then delete the score it is higher than and replace it.这意味着我将不得不使用某种操作来确定用户的分数是高于还是低于文件中的另一个分数,然后删除高于它的分数并替换它。 Any idea on how to do this?关于如何做到这一点的任何想法? I'm completely stuck.我完全被困住了。

Try Pseudeocode and work through steps.尝试伪代码并完成步骤。

  1. Get Score获得分数
  2. Compare Score比较分数
  3. Add Score添加分数

You have to think like a computer and break all the way down.您必须像计算机一样思考并彻底崩溃。 At each step think about how do I tell the computer to do that.在每一步都考虑如何告诉计算机这样做。 Once you have all that look at what you have done and remember DRY -> Don't Repeat Yourself.一旦你看完了你所做的一切并记住 DRY -> 不要重复你自己。 Your coding will go much faster.你的编码会更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM