Grading Students - Hackerrank Here is my solution to Grading Students courtesy of HackerRank. My code passes all tests in the testing suite but I feel like there could be a better implementation of it. But nonetheless, what are some pros/cons of my current implementation?
Thank you for answering. 

def gradingStudents(grades):
    rounded_grades = []
    for grade in grades:
        if grade &lt; 38:
            rounded_grades.append(grade)
        else:
            if grade % 5 == 0:
                rounded_grades.append(grade)
            else:
                difference = 0
                new_grade = grade
                while grade % 5 != 0:
                    difference += 1
                    new_grade += 1
                    if new_grade % 5 == 0:
                        break
                if difference &lt; 3:
                    rounded_grades.append(new_grade)
                else:
                    rounded_grades.append(grade)
    return rounded_grades
Your code is pretty good. Nice job.
I'd personally change the first else to an elif so you don't have as much indentation.
Rather than using that while loop you can just use one % per number.

For each number if you get the modulo then you can find out how much to add. 7 % 5 is 2. Where 5 - 2 is not less than 3.

And so you can easily change the while to just difference = 5 - grade % 5
You can merge grade % 5 == 0 into the else.
You can change the order and content of the ifs. This is as we don't need to call list.append three times, just mutate grade.


def gradingStudents(grades):
    rounded_grades = []
    for grade in grades:
        if grade &gt;= 38:
            difference = 5 - grade % 5
            if difference &lt; 3:
                grade += difference
        rounded_grades.append(grade)
    return rounded_grades


Since we know the range that anything modulo 5 is 0-4, we can just make a small lists that holds how much to round.

ADDITIONS = [0, 0, 0, 2, 1]


def gradingStudents(grades):
    rounded_grades = []
    for grade in grades:
        if grade &gt;= 38:
            grade += ADDITIONS[grade % 5]
        rounded_grades.append(grade)
    return rounded_grades


You can also change the code to a list comprehension if you're that way inclined.

ADDITIONS = [0, 0, 0, 2, 1]


def gradingStudents(grades):
    return [
        grade if grade &lt; 38 else grade + ADDITIONS[grade % 5]
        for grade in grades
    ]