def add_extension(fname, ext):
    """Add an extension ext to a file name if it is not already there, and
    returns the revised name. e.g. if fname='datafile' and ext='.dat', this
    returns 'datafile.dat'. If fname='datafile.dat', it still returns just
    'datafile.dat'.

    See: sub_extension
    """
    if len(ext) and not fname.endswith(ext):
        return f"{fname}{ext}"
    else:
        return fname