<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write(objct, fileoutput, binary=True):
 """ Write 3D object to file. Possile extensions are: - vtk, vti, ply, obj, stl, byu, vtp, xyz, tif, png, bmp. """

    obj = objct
    if isinstance(obj, Actor):
        obj = objct.polydata(True)
    elif isinstance(obj, vtk.vtkActor):
        obj = objct.GetMapper().GetInput()

    fr = fileoutput.lower()
    if ".vtk" in fr:
        w = vtk.vtkPolyDataWriter()
    elif ".ply" in fr:
        w = vtk.vtkPLYWriter()
    elif ".stl" in fr:
        w = vtk.vtkSTLWriter()
    elif ".vtp" in fr:
        w = vtk.vtkXMLPolyDataWriter()
    elif ".vtm" in fr:
        g = vtk.vtkMultiBlockDataGroupFilter()
        for ob in objct:
            g.AddInputData(ob)
        g.Update()
        mb = g.GetOutputDataObject(0)
        wri = vtk.vtkXMLMultiBlockDataWriter()
        wri.SetInputData(mb)
        wri.SetFileName(fileoutput)
        wri.Write()
        return mb
    elif ".xyz" in fr:
        w = vtk.vtkSimplePointsWriter()
    elif ".byu" in fr or fr.endswith(".g"):
        w = vtk.vtkBYUWriter()
    elif ".obj" in fr:
        w = vtk.vtkOBJExporter()
        w.SetFilePrefix(fileoutput.replace(".obj", ""))
        colors.printc("~target Please use write(vp.window)", c=3)
        w.SetInputData(obj)
        w.Update()
        colors.printc("~save Saved file: " + fileoutput, c="g")
        return objct
    elif ".tif" in fr:
        w = vtk.vtkTIFFWriter()
        w.SetFileDimensionality(len(obj.GetDimensions()))
    elif ".vti" in fr:
        w = vtk.vtkXMLImageDataWriter()
    elif ".png" in fr:
        w = vtk.vtkPNGWriter()
    elif ".jpg" in fr:
        w = vtk.vtkJPEGWriter()
    elif ".bmp" in fr:
        w = vtk.vtkBMPWriter()
    else:
        colors.printc("~noentry Unknown format", fileoutput, "file not saved.", c="r")
        return objct

    try:
        if not ".tif" in fr and not ".vti" in fr:
            if binary and not ".tif" in fr and not ".vti" in fr:
                w.SetFileTypeToBinary()
            else:
                w.SetFileTypeToASCII()
        w.SetInputData(obj)
        w.SetFileName(fileoutput)
        w.Write()
        colors.printc("~save Saved file: " + fileoutput, c="g")
    except Exception as e:
        colors.printc("~noentry Error saving: " + fileoutput, "\n", e, c="r")
    return objct