尝试将答案存储在文本文件中

时间:2014-12-02 14:35:13

标签: python python-3.x

我正在尝试制作一个将分数发送到文本文件的程序 你能帮到我的代码是

吗?
if cn == "1":
    fi = open("class1.txt","w")
    fi.write("\n" + str(name) + ":" + str(score))
    fi.close ()

1 个答案:

答案 0 :(得分:-2)

while questionNo == 10 and score >= 0:
    if schClass == '1':
     inFile = open("scores1.txt", 'a')
     inFile.write("\n" + name + " : " + str(score))
     inFile.close()
     score = -1
    elif schClass == '2':
     inFile = open("scores2.txt", 'a')
     inFile.write("\n" + name + " : " + str(score))
     inFile.close()
     score = -1
    elif schClass == '3':
     inFile = open("scores3.txt", 'a')
     inFile.write("\n" + name + " : " + str(score))
     inFile.close()
     score = -1