0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【python】得点を丸め込むプログラム

Posted at

#【python】得点を丸め込むプログラム

個人用メモです。

##設問

  • ①得点と②その得点の次の5の倍数との差が3未満(less than)の場合、①を丸め込んで②にする。
  • 得点が38未満(less than)の場合は丸め込みしない。

▼sample input

73
67
38
33

▼sample output

75
67
40
33

▼my answer

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()

■考え方
・次の5の倍数との差分が3未満になるのは、1の位が3,4,8,9の場合のみ。

■注意点
1桁の場合はパス。(2桁目が存在しない)
出力は配列で渡す。(配列をreturn)
「fptr.write('\n'.join(map(str, result)))」

※return gradeで返すと、メソッドが1回目の処理で終了してしまう。


・next multiple of n
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.

得点と、その得点に近い5の倍数の値の差分が3以下なら、その5の倍数の値に丸め込みをする。

・constraints
制約。数値の条件。
1<n<100 など

0
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?