def ext_checker(fname, ext):
    """Replaces the extension of fname with ext, or adds ext to fname
    if fname doesn't already have an extension."""
    ext_begin = -len(fname)
    for ind in range(1, len(fname) + 1):
        if fname[-ind] == ".":
            ext_begin = ind
            break
    return fname[:-ext_begin] + "." + ext