We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Grading Students
You are viewing a single comment's thread. Return to all 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 = []