def read_csv(file_name):
    with open(file_name, "r") as file:
        lines = file.readlines()
    data = []
    for line in lines:
        data.append(line.strip().split(";"))
        return data

def filter_reliable_students(pass_fail_data, count_data):
    reliable_students = []
    for i, student_results in enumerate(count_data[1:]):
        is_reliable = all([int(val) >= 10 if (val != '') and (pass_fail_data[i+1][j] == "VRAI") else True for j, val in enumerate(student_results)])
        if is_reliable:
            reliable_students.append(student_results)
        return reliable_students

def rank_exercises(pass_fail_data, count_data):
    reliable_students = filter_reliable_students(pass_fail_data, count_data)
    exercise_ranks = []
    for index, exercise_title in enumerate(pass_fail_data[0]):
        passed_students = 0
        for student_results in pass_fail_data[1:]:
            if student_results[index] == "VRAI" and student_results in reliable_students:
                passed_students += 1

        exercise_ranks.append((exercise_title, passed_students))

    return sorted(exercise_ranks, key=lambda x: (x[1], x[0]))

def main():
    pass_fail_file = "result-pass-fail-0.csv"
    count_file = "result-count-0.csv"

    pass_fail_data = read_csv(pass_fail_file)
    count_data = read_csv(count_file)

    print("----- Pass/fail data -----")
    for row in pass_fail_data:
        print(row)

    print("----- Count data -----")
    for row in count_data:
        print(row)

    ranked_exercises = rank_exercises(pass_fail_data, count_data)

    print("----- Ranked exercises -----")
    for exercise in ranked_exercises:
        print(exercise[0])

main() cela ne m'affiche que la premiere ligne