How to add user input fields to the UI, to be used by a Python script
You would need to create an operator to supply your script with parameter values.
This following script derived from the operator_mesh_add.py template (accessible from the template menu in the text editor):
Your code was simply copied into the scale function.

It creates an enum property to select the axis and a scale factor which can be entered from the UI in the last operator panel:



Look through the other templates for examples on how to add your operator to a menu, the object properties or whatever you like.

import bpy
from bpy.props import FloatProperty, EnumProperty


class ScaleAxis(bpy.types.Operator):
    """Scale axis """
    bl_idname = "mesh.primitive_scale"
    bl_label = "Scale axis"
    bl_options = {'REGISTER', 'UNDO'}

    axis  = EnumProperty(
            name="Axis",
            description="Axis selection",
            items= [('x', "X", ""),('y', "Y", ""),('z', "Z","")],
            default='x'
            )

    newdim = FloatProperty(
            name="Width",
            description="Scale",
            min=0.01, max=100.0,
            default=1.0,
            )
    # your code
    def scale(self, axis, new_dim):
        ob = bpy.context.active_object
        d = ob.dimensions

        x = d[0]
        y = d[1]
        z = d[2]

        scale =  axis

        if( scale == "x"):
            indice = 0
        elif( scale == "y"):
            indice = 1
        else:
            indice = 2

        old_dim = d[indice] 
        factor = new_dim / old_dim

        scale_x = ob.scale[0]
        scale_y = ob.scale[1]
        scale_z = ob.scale[2]

        ob.scale[0] = scale_x * factor
        ob.scale[1] = scale_y * factor
        ob.scale[2] = scale_z * factor

    def execute(self, context):
        self.scale(self.axis,self.newdim)
        return {'FINISHED'}


def menu_func(self, context):
    self.layout.operator(ScaleAxis.bl_idname, icon='MESH_CUBE')


def register():
    bpy.utils.register_class(ScaleAxis)
    bpy.types.INFO_MT_mesh_add.append(menu_func)


def unregister():
    bpy.utils.unregister_class(ScaleAxis)
    bpy.types.INFO_MT_mesh_add.remove(menu_func)

if __name__ == "__main__":
    register()


A nice tutorial