Grading Students

Sort by

recency

|

204 Discussions

|

  • + 0 comments

    Python 3:

    def gradingStudents(grades):
        curved = []
        for grade in grades:
            if grade < 38 or grade % 5 < 3:
                curved.append(grade)
            else:
                curved.append((grade - (grade % 5)) + 5)
        return curved``
    
  • + 0 comments

    For Java8:

    List gradeNew = new ArrayList<>();

    for(Integer grade: grades){

                if(grade>=38){
    
            if(grade%5>=3){
    
               grade =(grade/5+1)*5;
           }
        }
        gradeNew.add(grade);
    }
    return gradeNew;
    
  • + 0 comments

    Javascript solution

    function gradingStudents(grades) {
        // Write your code here
        return grades.map((grade) => {
            if (grade < 38) return grade;
            const remainder = grade % 5;
            if (remainder >= 3) return grade + (5 - remainder);
            else return grade
        })
    }
    
  • + 0 comments
    public static List<Integer> gradingStudents(List<Integer> grades) {
        // Write your code here
        List<Integer> newGrades = new ArrayList<Integer>();
        int students = grades.size();
        for(int i=0 ; i<students;i++){
            int factor = (grades.get(i)/5) + 1;
            if(grades.get(i)<38){
                newGrades.add(grades.get(i));
            }
            else if(factor*5 - grades.get(i) < 3){
                newGrades.add(factor*5);
            }
            else{
                newGrades.add(grades.get(i));
            }
        }
        return newGrades;
    
        }
    
  • + 0 comments

    Python 3 solution:

    def gradingStudents(grades: list[int]) -> list[int]:
        for i, grade in enumerate(grades):
            if grade > 37 and (mod_5 := grade % 5) > 2:
                grades[i] = grade + 5 - mod_5
        return grades