• + 0 comments

    There is an issue with the question. It assumes the input to have the first element as the number of students (not a grade). However, my code only worked when considering the first element (grades[0] in python)..

    Code

    def complement(x, m): return (m - (x % m)) % m

    def gradingStudents(grades): result = [] # Create a new list instead of modifying grades

    for grade in grades:
        if grade < 38 or grade % 5 < 3:
            result.append(grade)  # No rounding needed
        else:
            result.append(grade + complement(grade, 5))  #  Round up properly    
    return result  #  Return a new list