如何在python中将写入的东西添加到文件中

时间:2015-10-29 20:51:52

标签: 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()

1 个答案:

答案 0 :(得分:0)

当您以w作为模式打开文件时,会覆盖它。

您应该使用a打开文件,将文字附加到文件的末尾。