알고리즘 문제/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