DEV Community

loading...

Discussion on: Daily Challenge #54 - What century is it?

Collapse
matrossuch profile image
Mat-R-Such • Edited

python

def century (year):
    cent = str((year // 100) + 1)
    if int(cent) < 1:
        return "there isn't century"
    if cent[-1] == '1' :
        return cent+'st'
    elif cent[-1] == '2' and int(cent) != 12:
        return cent + 'nd'
    elif cent[-1] == '3':
        return cent + 'rd'
    else:
        return cent + 'th'