View Code of Problem 447

while True:
    try:
        n = input()
        for i in range(int(n)):
            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")
    except EOFError:
        break

Double click to view unformatted code.


Back to problem 447