• + 0 comments

    def gradingStudents(grades): """ Round grades according to the following rules: 1. If grade < 38, no rounding (failing grade) 2. If difference between grade and next multiple of 5 is < 3, round up 3. Otherwise, keep original grade """ result = []

    for grade in grades:
        if grade < 38:
            # Failing grades are not rounded
            result.append(grade)
        else:
            # Find the next multiple of 5
            next_multiple = math.ceil(grade / 5) * 5
            difference = next_multiple - grade
    
            if difference < 3:
                # Round up to next multiple of 5
                result.append(next_multiple)
            else:
                # Keep original grade
                result.append(grade)
    
    return result