[HackerRank] Grading Students


[質問]


Sam is a professor at the university and likes to round each student's according to these rules:
  • If the difference between the grades and the next multiple of 5 is less than 3, round grade up to the next multiple of 5.
  • If the value of grade is less than 38, no rounding occurs as the result will still be a failing grade.
  • [入力]


    The first line contains a single integer n , the number of students.
    Each line i of the n subsequent lines contains a single integer, grades[i].

    [出力]


    int[n] : the grades after rounding as appropriate.

    [コード]

    def gradingStudents(grades):
        # Write your code here
        for i in range(len(grades)):
            if(grades[i]<38):
                continue
            else:
                up = (grades[i]//5)+1;
                if((up*5) - grades[i] < 3):
                    grades[i] = up*5
        return grades