HackerLand University Has The Following Grading Policy: – Every Student Receives A Grade In The Inclusive Range From 0 To 100. – Any Grade Less Than 40 Is A Failing Grade. Sam Is A Professor At The University And Likes To Round Each Student’s Grade According To These Rules: – If The Difference Between The Grade And The Next Multiple Of 5 Is Less Than 3 ,
solve this code in python3HackerLand University Has The Following Grading Policy: – Every Student Receives A Grade In The Inclusive Range From 0 To 100. – Any Grade Less Than 40 Is A Failing Grade. Sam Is A Professor At The University And Likes To Round Each Student’s Grade According To These Rules: – If The Difference Between The Grade And The Next Multiple Of 5 Is Less Than 3 ,
Expert Answer
Below is the complete code in Python for the above program:
def gradingStudents(grades):
rounded_grades = []
for grade in grades:
if grade < 38:
# Grades below 38 are failing and not rounded
rounded_grades.append(grade)
else:
next_multiple_of_5 = (grade // 5 + 1) * 5
if next_multiple_of_5 - grade < 3:
# If the difference is less than 3, round up
rounded_grades.append(next_multiple_of_5)
else:
# Otherwise, keep the original grade
rounded_grades.append(grade)
return rounded_grades
# Input the number of students
n = int(input())
grades = []
for _ in range(n):
grade = int(input())
grades.append(grade)
# Call the gradingStudents function and print the results
rounded_grades = gradingStudents(grades)
for grade in rounded_grades:
print(grade)
OR