|
| 1 | +# HackerLand University has the following grading policy: |
| 2 | + |
| 3 | +# Every student receives a in the inclusive range from to . |
| 4 | +# Any less than is a failing grade. |
| 5 | +# Sam is a professor at the university and likes to round each student's according to these rules: |
| 6 | + |
| 7 | +# If the difference between the and the next multiple of is less than , round up to the next multiple of . |
| 8 | +# If the value of is less than , no rounding occurs as the result will still be a failing grade. |
| 9 | +# For example, will be rounded to but will not be rounded because the rounding would result in a number that is less than . |
| 10 | + |
| 11 | +# Given the initial value of for each of Sam's students, write code to automate the rounding process. |
| 12 | + |
| 13 | +# Function Description |
| 14 | + |
| 15 | +# Complete the function gradingStudents in the editor below. It should return an integer array consisting of rounded grades. |
| 16 | + |
| 17 | +# gradingStudents has the following parameter(s): |
| 18 | + |
| 19 | +# grades: an array of integers representing grades before rounding |
| 20 | +# Input Format |
| 21 | + |
| 22 | +# The first line contains a single integer, , the number of students. |
| 23 | +# Each line of the subsequent lines contains a single integer, , denoting student 's grade. |
| 24 | + |
| 25 | +# Constraints |
| 26 | + |
| 27 | +# Output Format |
| 28 | + |
| 29 | +# For each , print the rounded grade on a new line. |
| 30 | + |
| 31 | +# Sample Input 0 |
| 32 | + |
| 33 | +# 4 |
| 34 | +# 73 |
| 35 | +# 67 |
| 36 | +# 38 |
| 37 | +# 33 |
| 38 | +# Sample Output 0 |
| 39 | + |
| 40 | +# 75 |
| 41 | +# 67 |
| 42 | +# 40 |
| 43 | +# 33 |
| 44 | +# Explanation 0 |
| 45 | + |
| 46 | +# image |
| 47 | + |
| 48 | +# Student received a , and the next multiple of from is . Since , the student's grade is rounded to . |
| 49 | +# Student received a , and the next multiple of from is . Since , the grade will not be modified and the student's final grade is . |
| 50 | +# Student received a , and the next multiple of from is . Since , the student's grade will be rounded to . |
| 51 | +# Student received a grade below , so the grade will not be modified and the student's final grade is . |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +#!/bin/python3 |
| 71 | + |
| 72 | +import math |
| 73 | +import os |
| 74 | +import random |
| 75 | +import re |
| 76 | +import sys |
| 77 | + |
| 78 | +# |
| 79 | +# Complete the 'gradingStudents' function below. |
| 80 | +# |
| 81 | +# The function is expected to return an INTEGER_ARRAY. |
| 82 | +# The function accepts INTEGER_ARRAY grades as parameter. |
| 83 | +# |
| 84 | + |
| 85 | +def gradingStudents(grades): |
| 86 | + list1 = [] |
| 87 | + for i in range(0,len(grades)): |
| 88 | + if(grades[i] < 38): |
| 89 | + # list1.append(grades[i]) |
| 90 | + grades[i] = grades[i] |
| 91 | + else: |
| 92 | + if((grades[i]+1)%5 == 0): |
| 93 | + grades[i] = grades[i]+1 |
| 94 | + elif((grades[i]+2)%5 == 0): |
| 95 | + grades[i] = grades[i]+2 |
| 96 | + else: |
| 97 | + grades[i] = grades[i] |
| 98 | + |
| 99 | + return(grades) |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | +if __name__ == '__main__': |
| 108 | + fptr = open(os.environ['OUTPUT_PATH'], 'w') |
| 109 | + |
| 110 | + grades_count = int(input().strip()) |
| 111 | + |
| 112 | + grades = [] |
| 113 | + |
| 114 | + for _ in range(grades_count): |
| 115 | + grades_item = int(input().strip()) |
| 116 | + grades.append(grades_item) |
| 117 | + |
| 118 | + result = gradingStudents(grades) |
| 119 | + |
| 120 | + fptr.write('\n'.join(map(str, result))) |
| 121 | + fptr.write('\n') |
| 122 | + |
| 123 | + fptr.close() |
0 commit comments