<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_segwizard(segs, target, header=True, coltype=LIGOTimeGPS):
 """Write the given `SegmentList` to a file in SegWizard format. Parameters segs : :class:`~gwpy.segments.SegmentList` The list of segments to write. target : `file`, `str` An open file, or file path, to which to write. header : `bool`, optional Print a column header into the file, default: `True`. coltype : `type`, optional The numerical type in which to cast times before printing. Notes ----- This method is adapted from original code written by Kipp Cannon and distributed under GPLv3. """

    # write file path
    if isinstance(target, string_types):
        with open(target, 'w') as fobj:
            return to_segwizard(segs, fobj, header=header, coltype=coltype)

    # write file object
    if header:
        print('# seg\tstart\tstop\tduration', file=target)
    for i, seg in enumerate(segs):
        a = coltype(seg[0])
        b = coltype(seg[1])
        c = float(b - a)
        print(
            '\t'.join(map(str, (i, a, b, c))),
            file=target,
        )