[Python] A program that rounds the score

[Python] A program that rounds the score

This is a personal memo.

question

--If the difference between (1) the score and (2) the next multiple of 5 of the score is less than 3, round (1) to (2). --If the score is less than 38 (less than), it will not be rounded.

▼sample input

python


73
67
38
33

▼sample output

python


75
67
40
33

▼my answer

python


def gradingStudents(grades):
    finals=[]
    for grade in grades:
        if grade >= 38:
            a = str(grade)[1]
            if a == "3":
                grade += 2
            elif a=="4":
                grade += 1
            elif a=="8":
                grade += 2
            elif a=="9":
                grade += 1
        finals.append(grade)
    return finals


if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], '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()

■ Way of thinking -The difference from the next multiple of 5 is less than 3 only when the 1st place is 3,4,8,9.

■ Notes Pass for 1 digit. (The second digit does not exist) The output is passed as an array. (Return array) 「fptr.write('\n'.join(map(str, result)))」


** ・ next multiple of n ** A multiple of n.

If the difference between the grade and the next multiple of 5 is less than 3, round up to the next multiple of 5.

If the difference between the score and a value that is a multiple of 5 that is close to that score is 3 or less, the value that is a multiple of 5 is rounded.

** ・ constraints ** Constraints. Numerical conditions. 1 <n <100 etc.

Recommended Posts

[Python] A program that rounds the score
[Python] A program that counts the number of valleys
[Python] A program that compares the positions of kangaroos.
[Python] A program that finds the most common bird types
[Python] A program that creates stairs with #
A program that plays rock-paper-scissors using Python
[Ev3dev] Create a program that captures the LCD (screen) using python
[Python] A program that rotates the contents of the list to the left
A program that removes duplicate statements in Python
A program that searches for the same image
A shell program that displays the Fibonacci sequence
[Python] A program that calculates the number of chocolate segments that meet the conditions
[Python] A program that calculates the number of socks to be paired
Python program that looks for the same file name
[Python] A program that finds the minimum and maximum values without using methods
[Python] A program that calculates the difference between the total numbers on the diagonal line.
[Python] A program that calculates the number of updates of the highest and lowest records
A memo that I touched the Datastore with python
A Python program that converts ical data into text
[Python] A program that finds the shortest number of steps in a game that crosses clouds
A program that summarizes the transaction history csv data of SBI SECURITIES stocks [Python3]
There is a pattern that the program did not stop when using Python threading
A note that runs an external program in Python and parses the resulting line
A Python program in "A book that gently teaches difficult programming"
A general-purpose program that formats Linux command strings in python
A program that removes specific characters from the entered text
Write a python program to find the editing distance [python] [Levenshtein distance]
Creating a Python script that supports the e-Stat API (ver.2)
I tried "a program that removes duplicate statements in Python"
[Python] A program that creates a two-dimensional array by combining integers
A program that just presses and releases the Esc key
A Python program that aggregates time usage from icalendar data
[Golang] A program that determines the turn with random numbers
A Python script that compares the contents of two directories
[Python] Make the function a lambda function
When writing a program in Python
The story of writing a program
A program that automatically resizes the iOS app icon to the required image size in Python
[Python] A program to find the number of apples and oranges that can be harvested
Play a sound in Python assuming that the keyboard is a piano keyboard
I made a program that solves the spot the difference in seconds
A story that struggled to handle the Python package of PocketSphinx
From a book that programmers can learn (Python): Find the mode
A function that measures the processing time of a method in python
Read a file in Python with a relative path from the program
Try to write a program that abuses the program and sends 100 emails
[Python algorithm] A program that outputs Sudoku answers from a depth-first search
A script that returns 0, 1 attached to the first Python prime number
A program that answers a few questions and predicts the next answer
[python] A note that started to understand the behavior of matplotlib.pyplot
The story of making a module that skips mail with python
Create a compatibility judgment program with the random module of python.
Understand the probabilities and statistics that can be used for progress management with a python program
[Python] I tried to make a simple program that works on the command line using argparse.
[Python] A program that finds the maximum number of toys that can be purchased with your money
[python] Move files that meet the conditions
A class that hits the DMM API
I made a payroll program in Python!
Python3 + pyperclip that rewrites the copied text
Run the Python interpreter in a script
Write a Caesar cipher program in Python