<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_file(filepath, encoding, gzipped, data):
 """ Write the data to file either as a gzip file or text based on the gzipped parameter Args: filepath (str):
 The filename to open encoding (str):
 The file encoding to use gzipped (bool):
 Whether the file should be gzipped or not data (str):
 The data to be written out """

    if gzipped:
        with gzip.open(filepath, "wt") as fobj:
            fobj.write(data)
    else:
        with OPEN(filepath, "w", encoding=encoding) as fobj:
            if sys.version_info < (3, 0):
                data = data.decode(encoding)
            fobj.write(data)