dimanche 12 avril 2020

Find names from 2 lists python using for loop

Hello

I want to make a for loop that adds classes into a list when the class requirements are met until the max_credit is hit. class_list lists all the classes with their credits, co-requisite classes, required classes, and the last cell is open because I want to use it for later.

class_list = [['MA 241 ', '4', '', '', ''], ['PS 150 ', '3', 'MA 241 ', '', ''], ['UNIV 101', '1', '', '', ''], ['COM 122', '3', '', '', ''], ['MA 242', '4', '', 'MA 241 ', ''],  ['PS 160', '3', 'MA 242', 'PS 150 ', '']]
class_done = ['UNIV 101', 'MA 241', [], [], [], [], [], []]
classes_for_semester=[]
credits_for_semester=0
max_credit_allowed=16

Now I want to add the class to the classes_for_semester if either the co-requisite class is in the classes_for_semester or the required class is in class_done.

I was thinking this would work, but it doesn't seem to get into the second If statement:

for i in range(len(class_list)):
    if int(class_list[i][1])+credits_for_semester < max_credit_allowed:
        if class_list[i][3] == '' or class_list[i][3] in class_done or class_list[i][2] in classes_for_semester:
            print(class_list[i][0])
            classes_for_semester.append(class_list[i][0])
            credits_for_semester += int(class_list[i][1])
            print(True)

Maybe you could help me figure out what I am doing wrong. If you are going to post a solution that would be great but please give an explanation :), because as you can probably tell I am quite new at this and I want to understand it.

Much appreciated

Aucun commentaire:

Enregistrer un commentaire