2015-10-29 40 views
0

這是我創建的遊戲。它應該爲文件添加一個新的分數,但它只是覆蓋它,我不知道如何解決它。如何在Python中將文字添加到文件中

input("HIT ENTER WHEN YOU ARE READY") 



    #Makes the while Statment repeating it selve 
    c= True 

    #Repeating it selve 
    while c == True: 

     import time 

     One = time.time() 
     a=input("Type as fast the alphabet (Either Caps or all small letters!): ") 
     b= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 
     d= 'abcdefghijklmnopqrstuvwxyz' 



     if a == b or a == d: 
     Two = time.time() 
     difference = int(Two - One) 
     print("Well done your time is",difference,"seconds") 
     c = False 
     else: 
     print('Arg Wrong the time is still running!') 
     a=input(" ") 
     C = True 




    #Writes the sore to a file 
    "Score.txt" 

    def writeToFile(): 
     global myFile 

    difference = str(difference) 
    myFile = open("Score.txt","w") 
    myFile.write(difference + '\n') 
    myFile.close() 
+0

將文件打開模式從'w'(寫入)更改爲'a'(追加):'myFile = open(「Score.txt」,「a」)' – stevieb

回答

0

當您使用w作爲模式打開文件時,將覆蓋它。

您應該使用a打開文件以將文本附加到文件末尾。

相關問題