bestscore在python空闲

时间:2017-09-16 11:34:05

标签: python

我有一个游戏,而不是想要一个高分函数,我想要一个lowscore函数。

到目前为止,我还没有看到一个有效的lowscore功能,所以我试图创建自己的,但我是一个相当新的程序员

def reaction():
    import time
    import sys
    print("Split second reaction")
    print("*********************")
    time.sleep(1)
    print("Ready")
    time.sleep(1)
    print("Set")
    time.sleep(1)
    print("Go!")
    start = time.time()
    g=input()
    end = time.time()
    score=end - start
    highscore=open("record is in this document:")
    if score<highscore:
       print("New Highscore! "))
       highscore=score
    else:
       print("Highscore:",highscore)

reaction()

1 个答案:

答案 0 :(得分:0)

当找到更好的分数时,即得分&lt;记录,您应该将结果保存在同一个文件中。请参阅以下代码:

def reaction():
    import time
    import sys
    print("Split second reaction")
    print("*********************")
    time.sleep(1)
    print("Ready")
    time.sleep(1)
    print("Set")
    time.sleep(1)
    print("Go!")
    start = time.time()
    g=input()
    end = time.time()
    score=end - start
    with open("data.txt") as file:
       highscore = float(file.readline())
    if score<highscore:
       with open("data.txt", "w") as file:
         file.write(str(score))
         print("New Highscore! ")
    else:
       print("Highscore:",highscore)

reaction()