Python测验得分

时间:2017-11-09 03:08:04

标签: python

我正在为测验制作一个评分系统。它不会增加分数。运行时显示0。

def startquizm():
    dateFile = open("maths.txt", "r")
    score=0

    for line in dateFile:
        data = line.split(",")
        print("Question:" , data[0])
        print("Option 1:" , data[1])
        print("Option 2:" , data[2])
        print("Option 3:" , data[3])
        print("Option 4:" , data[4])

        ua=input("what is your answer? ")

        #answer = data[5]
        print(data[5])

        if data[5]==ua:
            score=score+1
        print(score)

    dateFile.close()                          


startquizm()

输出

What is 3 + 8?,11,10,12,13,11
What is 4 + 2?,6,4,5,7,6
What is 4 x 6?,24,30,20,10,24
What is 8 x 4?,32,12,30,48,32
What is 12 / 3?,4,3,36,1,4

1 个答案:

答案 0 :(得分:0)

def startquizm():
    dateFile = open("maths.txt", "r")
    score=0

for line in dateFile:
    data = line.split(",")
    print("Question:" , data[0])
    print("Option 1:" , data[1])
    print("Option 2:" , data[2])
    print("Option 3:" , data[3])
    print("Option 4:" , data[4])

    ua=input("what is your answer? ")

    #answer = data[5]
    print(data[5])

    if int(data[5])==int(ua): # try cast them to integer
        score=score+1
    print(score)

dateFile.close()    

尝试将它们转换为整数