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.
Grading Students
Grading Students
Sort by
recency
|
3968 Discussions
|
Please Login in order to post a comment
Here is my c++ solution, you can find video here : https://youtu.be/fYcSakw_5-M
For Javascript :
For Java, I liked the idea of just doing the math in a ternary, rounding the grade up, and adding it to the List all in a one-liner, here ->
finalRoundedGrades.add( ( ( 5 - (g % 5) ) < 3) ? g + ( 5 - (g % 5) ) : g );
Where g is the grade: 5 - (g % 5) ) < 3 ? : if the remainder of dividing the grade g by 5 is less than 3 (i.e., if the number in the 'ones' place (the number just to the left of the decimal point, if there were one) ends in 8, 9, or 0, where the remainders are 2, 1, or 0, respectively)... g + ( 5 - (g % 5) ) : round g up by adding that remainder to the grade... : g : otherwise, g remains g
/* -------- With C# -------- */
def gradingStudents(grades): adjusted_grades = [] for grade in grades: next_multiple5 = ((grade//5)+1)*5 diff = next_multiple5 - grade if (grade >= 38) and (diff <3): adjusted_grades.append(next_multiple5) else: adjusted_grades.append(grade) return adjusted_grades