This is a very C-like way of doing things. In Python you would use what is known as a function. Below is an example in Ruby, I'll leave the Python implementation as an exercise.

    def ordinalize(number)
      if (11..13).include?(number.to_i % 100)
        "#{number}th"
      else
        case number.to_i % 10
          when 1; "#{number}st"
          when 2; "#{number}nd"
          when 3; "#{number}rd"
          else    "#{number}th"
        end
      end
    end

Source: http://apidock.com/rails/Inflector/ordinalize