Loading

Century From Year(这年属于哪个世纪?)

Introduction
The first century spans from the year 1 up to and including the year 100, the second century - from the year 101 up to and including the year 200, etc.
Task
Given a year, return the century it is in.
Examples
1705 --> 18
1900 --> 19
1601 --> 17
2000 --> 20
Solution

def century(year): 
    return (year - 1) // 100 + 1
# 这里,// 表示整除,% 表示取余数。
# 例如,1705 // 100 = 17,1705 % 100 = 5,
# 所以 (1705 - 1) // 100 + 1 = 18。
# 1705表示第18个世纪
posted @ 2023-03-12 12:00  Artwalker  阅读(25)  评论(0)    收藏  举报
Live2D