DEV Community

Discussion on: Daily Challenge #296 - Years to Centuries

Collapse
 
matrossuch profile image
Mat-R-Such

Py <3

def what_century(year):
    c, r = divmod(year,100)

    if r > 0:   c += 1

    #name 

    if c in [11,12,13]:         return str(c)+'th'
    elif str(c)[-1] == '1':     return str(c)+'st'
    elif str(c)[-1] == '2':     return str(c) + 'nd'
    elif str(c)[-1] == '3':     return str(c) + 'rd'
    else:                        return str(c) + 'th'
Enter fullscreen mode Exit fullscreen mode