Grading Students - Hackerrank
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
    ]