如何以递增顺序显示结果

时间:2019-06-23 18:30:19

标签: python

此代码按顺序显示结果,但我需要按升序显示它们,但无法弄清楚该怎么做。

我尝试过list.sort,但是插入时我的代码就中断了。

#main function
def main():

    #student’s answer to the questions
    answers = [
        ['A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'],
        ['D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'],
        ['E', 'D', 'D', 'A', 'C', 'B', 'E', 'E', 'A', 'D'],
        ['C', 'B', 'A', 'E', 'D', 'C', 'E', 'E', 'A', 'D'],
        ['A', 'B', 'D', 'C', 'C', 'D', 'E', 'E', 'A', 'D'],
        ['B', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'],
        ['B', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'],
        ['E', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D']]

    #key to the questions
    key = ['D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D']

    #declare studentScores as list type variable
    studentScores = list()
    students = list()

    #grade all answers
    for i in range(len(answers)):
        #grade one student
        correctCount = 0

        for j in range(len(answers[i])):
            if answers[i][j] == key[j]:
                correctCount += 1

        #append to correctCount to studentScore list
        studentScores.append(correctCount)

        #append i to students list
        students.append(i)

    #iterate the loop
    for i in students:
        print("student:",i, "‘s correct count is: ",studentScores[i])

#call the main function
main()

我希望正确计数的输出按递增顺序(4,5,6,7,7,7,7,7,8)而不是按输入顺序(7,6,5,4,8,7, 7,7)。

0 个答案:

没有答案