在python中修复排行榜

时间:2019-05-28 00:41:20

标签: python python-3.x leaderboard

只要有人完成测验,就不会显示其分数。它将删除并显示其他所有人。但这确实表明他们是其他人下次玩的。我该如何解决?我比较新。我尝试更改某些内容,但始终会导致错误消息!任何帮助/建议都很棒。

import time
start1 = time.time()
            question_af1 = ("How many countries are in Africa?")
            option_af1 =(" a. 54 \n b. 50 \n c. 47 \n d. 38")
            print(question_af1)
            print(option_af1)    
            answer_af1 = input(">")        
            if answer_af1.lower() == "a":
                score += 100
                print("Correct, score =", score)#add time not used
                #print(end - start) will show seconds completed
            else:
                print("Incorrect") #the correct answer is

            question_af2 = ("What is the largest country in Africa?")
            option_af2 = (" a. Algeria \n b. Sudan \n c. Ethiopia \n d. Zimbabwe")


            end1 = time.time()
            print(round(end1 - start1,2))###finish fixing time
            print("Score =", score)

            import csv

            score=score
            username=name

            with open ("leaderboard1.csv", "a", newline='') as file:
                fields=['score', 'name']
                writer=csv.DictWriter(file, fieldnames=fields)
                writer.writerow({'score' : score, 'name' : username})

            with open ("leaderboard1.csv", "r") as file:
                sortlist=[]
                reader=csv.reader(file)
                for i in reader:
                    sortlist.append(i)
            for i in range(len(sortlist)):
                if i != 0:
                    sortlist[i][0]=int(sortlist[i][int(0)])


            print("")
            for i in range(len(sortlist)):
                (sortlist[i])


            for i in range(555):
                for i in range(len(sortlist)):
                    if i != 0:
                        if sortlist[i][0] < sortlist[i+1][0]-1:
                            change=sortlist[i]
                            sortlist[i]=sortlist[i+1]
                            sortlist[i+1]=change

0 个答案:

没有答案