View Code of Problem 447

while True:
    x = input()
    if len(x) > 1:
        if x[-2] == '1':
            print(x + "th")
        else:
            if x[-1] == '1':
                print(x + "st")
            elif x[-1] == '2':
                print(x + "nd")
            elif x[-1] == '3':
                print(x + "rd")
            else:
                print(x + "th")
    else:
        if x[-1] == '1':
            print(x + "st")
        elif x[-1] == '2':
            print(x + "nd")
        elif x[-1] == '3':
            print(x + "rd")
        else:
            print(x + "th")

Double click to view unformatted code.


Back to problem 447