물음표 살인마의 개발블로그

알고리즘 문제/CodeWar

What century is it?

BEstyle 2022. 11. 4. 13:18

DESCRIPTION:

Return the century of the input year. The input will always be a 4 digit string, so there is no need for validation.

Examples

"1999" --> "20th"
"2011" --> "21st"
"2154" --> "22nd"
"2259" --> "23rd"
"1124" --> "12th"
"2000" --> "20th"

def what_century(y):
    print(y)
    if y[-1]=="0" and y[-2]=="0":
        c=y[0:2]
    else:
        print("1")
        c=str(int(y[0:2])+1)
    if c[-2]=="1":
        c+="th"
    elif c[-1]=="1":
        c+="st"
    elif c[-1]=="2":
        c+="nd"
    elif c[-1]=="3":
        c+="rd"
    else:
        c+="th"
    print(c)
    return c

'알고리즘 문제 > CodeWar' 카테고리의 다른 글

Delete a digit  (0) 2022.11.04
Mean Square Error  (0) 2022.11.04
Arrh, grabscrab!  (0) 2022.11.02
Calculating String Rotation  (0) 2022.11.02
Coding Meetup #8 Will all continents be represented?  (0) 2022.11.02