Python 3.4:列表中列表的最小值和最大值不正确 我正在创建代码,输出每个学生的最低和最高分数。代码首先从文件中读取,然后将其存储在列表中:

Python 3.4:列表中列表的最小值和最大值不正确 我正在创建代码,输出每个学生的最低和最高分数。代码首先从文件中读取,然后将其存储在列表中:,python,max,min,nested-lists,Python,Max,Min,Nested Lists,[Georgina Cottrell][4][10][8][Amelia Cox][6][4][8][Jack Elsom][8][9][10][Isabella Jones][2][8][4] 当尝试查找最小值和最大值时,它仅适用于某些列表。以下是一个输出示例: [['Amelia Cox',6,4,8,4,6],'Georgina Cottrell',4,10,8,4,10],'Isabella Jones',2,8,4,2,8],'Jack Elsom',8,9,10,8,9]] 正如你所

[Georgina Cottrell][4][10][8][Amelia Cox][6][4][8][Jack Elsom][8][9][10][Isabella Jones][2][8][4]

当尝试查找最小值和最大值时,它仅适用于某些列表。以下是一个输出示例:

[['Amelia Cox',6,4,8,4,6],'Georgina Cottrell',4,10,8,4,10],'Isabella Jones',2,8,4,2,8],'Jack Elsom',8,9,10,8,9]]

正如你所看到的,我的代码没有识别出一些最小值和一些最大值

这是我的密码:

    def menu():
        global user_password
        if user_password == correct_password:
            classes = input("Which class would you like to view? :")
            classes = classes.lower()
            while classes not in ["3a", "4a", "5a"]:
                time.sleep(2)
                classes = input("Input invalid. Please enter 3a, 4a or 5a: ")
                if classes == ["3a", "4a", "5a"]:
                    break
            if classes == "3a":
                file = open("scores3a.csv", "r")
                csv_f = csv.reader(file)
                yourlists = list(csv_f)
                file.close()
                yourlists2 = [x for x in yourlists if x]
                print("-------------------------------------------------------------\n"
                      "Welcome to the menu sytem to view your students scores.\n"
                      "-------------------------------------------------------------\n"
                      "Type the corresponding letter for what you would like to view:\n")
                time.sleep(2)
                all_scores = print("Input 'a' to see all of your students scores in alphabetical order(by forename)\n"
                                   "and sorted into highest to lowest scores for each student")
        time.sleep(2)
        highest_scores = print("Input 'b' to see all of the students average scores\n"
                               "sorted into highest to lowest")
                user = input()
                if user == "a":
                    yourlists2.sort()
                    slices = yourlists2[0][:]
                    slices1 = yourlists2[1][:]
                    slices2 = yourlists2[2][:]
                    slices3 = yourlists2[3][:]
                    for row in slices:
                        slices[1]=int(slices[1])
                        slices[2]=int(slices[2])
                        slices[3]=int(slices[3])
                        lowest = min(slices[1:3])
                        slices.append(lowest)
                        highest =  max(slices[1:3])
                        slices.append(highest)
                        break
                    for row in slices1:
                        slices1[1]=int(slices1[1])
                        slices1[2]=int(slices1[2])
                        slices1[3]=int(slices1[3])
                        lowest = min(slices1[1:3])
                        slices1.append(lowest)
                        highest =  max(slices1[1:3])
                        slices1.append(highest)
                        break
                    for row in slices2:
                        slices2[1]=int(slices2[1])
                        slices2[2]=int(slices2[2])
                        slices2[3]=int(slices2[3])
                        lowest = min(slices2[1:3])
                        slices2.append(lowest)
                        highest =  max(slices2[1:3])
                        slices2.append(highest)
                        break
                    for row in slices3:
                        slices3[1]=int(slices3[1])
                        slices3[2]=int(slices3[2])
                        slices3[3]=int(slices3[3])
                        lowest = min(slices3[1:3])
                        slices3.append(lowest)
                        highest =  max(slices3[1:3])
                        slices3.append(highest)
                        break
                    yourlists2=[slices,slices1,slices2,slices3]
                    print(yourlists2)


    menu()                

如果有人能帮忙,我会非常感激的。谢谢!:)

请注意,
slices[1:3]
是长度为2的列表:它只包含
slices[1]
slices[2]
(结束索引不包括在内)。你可能想要
切片[1::]
切片[1:4]
。当然!这已经困扰了我好几天了,就这么简单!非常感谢。请注意,
slices[1:3]
是一个长度为2的列表:它只包含
slices[1]
slices[2]
(结尾索引不包括在内)。你可能想要
切片[1::]
切片[1:4]
。当然!这已经困扰了我好几天了,就这么简单!非常感谢你。