-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-Grading_Students.py
61 lines (45 loc) · 1.53 KB
/
11-Grading_Students.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 20 2023
@author Carlos Páez
"""
import random
import sys
import math
#
# Complete the 'gradingStudents' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts INTEGER_ARRAY grades as parameter.
#
def _round_up_to_next_multiple_of_5(x: int) -> int:
"""
It takes a number, divides it by 5, rounds it up, and then multiplies it by 5
:param x: the number to round
:return: the value of 5 times the ceiling of x divided by 5.
"""
return 5 * math.ceil(x/5)
def gradingStudents(grades: list[int]) -> list[int]:
"""
If the grade is less than 38, return the grade. If the grade is greater than or equal to 38, round
up to the next multiple of 5 and return that if the difference between the grade and the next
multiple of 5 is less than 3. Otherwise, return the grade
:param grades: an array of integers representing grades before rounding
:return: a list of rounded grades.
"""
return [
_round_up_to_next_multiple_of_5(grade) if grade >= 38 and _round_up_to_next_multiple_of_5(grade) - grade < 3
else grade
for grade in grades
]
if __name__ == '__main__':
fptr = open('./output.txt', 'w')
grades_count = int(input().strip())
grades = []
for _ in range(grades_count):
grades_item = int(input().strip())
grades.append(grades_item)
result = gradingStudents(grades)
fptr.write('\n'.join(map(str, result)))
fptr.write('\n')
fptr.close()