如何在python中向文件中添加编写的内容

2024-09-29 17:17:55 发布

您现在位置: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()

Tags: orthetrueinputtimeisitmyfile

热门问题