2015-10-29 38 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打开文件以将文本附加到文件末尾。

相关问题