2017-09-16 52 views
0

我有一個遊戲,我做了,而不是想要高分功能我想要一個低分功能。python中的bestscore Idle

我還沒有看到一個工作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

你的輸出是什麼? – Adi219

+0

帶記錄號的記事本文件 –

+0

您看到什麼發生,您想要發生什麼? –

回答

0

當一個更好的成績被發現,那就是得分<記錄,你應該將結果保存在同一個文件中。見下面的代碼:

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() 
+0

我該怎麼做 –

+0

它不起作用 –

+0

您需要在同一位置有一個名爲data.txt的文件,您有.py文件。 data.txt文件中還應該有一個數字 –