나는 리플렉스 테스트 게임을 가지고 있으며 그 사이에 공백이있는 사용자의 이름과 점수를 저장하는 텍스트 파일을 설정했습니다. 수치가 가장 낮은 7.45텍스트 파일에서 순위표를 읽고 점수가 가장 낮은 점수부터 최고 점수까지 정렬하는 방법은 무엇입니까?
I 스티브 맨 위에 있고 아래
예
벤에서 가장 높은 1.43
에릭 3.53
있도록 어떻게 숫자로 텍스트 파일을 정렬 할 2 자리 소수 자릿수를 포함하고 싶습니다.
코드 : 이것은 당신이 필요로하는 종류의 어떤 종류의 당신을 도울 것입니다이 링크 https://wiki.python.org/moin/HowTo/Sorting 에서
import time
import random
global start
global end
global score
def gameBegin():
print('***************')
print('* Reflex Game *')
print('***************')
print("\nPress Enter as soon as you see the word 'stop'.")
print('Press Enter to Begin')
input()
def gameStart():
global start
global end
time.sleep(random.randint(1,1))
start = time.time()
input('STOP')
end = time.time()
def gameScore():
global start
global end
global score
score=round(end-start,2)
print (score)
def scorePrint():
global score
with open("Leaderboards.txt", "r+") as board:
print (board.read())
def boardEdit():
global score
name = input('Enter Your Name For The Leader Board : ')
board = open ("Leaderboards.txt","a+")
board.write(name)
board.write(" ")
board.write(str(score))
def boardSort():
#HELP
gameBegin()
gameStart()
gameScore()
scorePrint()
boardEdit()
boardSort()
내 대답을 편집했습니다. 더 효율적인 응답을 만들기 위해 더 이상 변경해야 할 경우 알려주십시오. –
멋지게 완료되었습니다. 잘 했어. –
어떻게 텍스트 파일을 정렬합니까? – Dargon111