<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_iso6709(latitude, longitude, altitude=None, format='dd', precision=4):
 """Produce ISO 6709 coordinate strings. This function will produce ISO 6709-1983(E) "Standard representation of latitude, longitude and altitude for geographic point locations" elements. See also: from_iso6709 Args: latitude (float):
 Location's latitude longitude (float):
 Location's longitude altitude (float):
 Location's altitude format (str):
 Format type for string precision (int):
 Latitude/longitude precision Returns: str: ISO 6709 coordinates string Raises: ValueError: Unknown value for ``format`` .. _Latitude, Longitude and Altitude format for geospatial information: http://www.w3.org/2005/Incubator/geo/Wiki/LatitudeLongitudeAltitude .. _wikipedia ISO 6709 page: http://en.wikipedia.org/wiki/ISO_6709 """

    text = []
    if format == 'd':
        text.append('%+03i%+04i' % (latitude, longitude))
    elif format == 'dd':
        text.append('%+0*.*f%+0*.*f' % (precision + 4, precision, latitude,
                                        precision + 5, precision, longitude))
    elif format in ('dm', 'dms'):
        if format == 'dm':
            latitude_dms = to_dms(latitude, 'dm')
            longitude_dms = to_dms(longitude, 'dm')
        elif format == 'dms':
            latitude_dms = to_dms(latitude)
            longitude_dms = to_dms(longitude)
        latitude_sign = '-' if any(i < 0 for i in latitude_dms) else '+'
        latitude_dms = tuple(abs(i) for i in latitude_dms)
        longitude_sign = '-' if any(i < 0 for i in longitude_dms) else '+'
        longitude_dms = tuple(abs(i) for i in longitude_dms)
        if format == 'dm':
            text.append('%s%02i%02i' % ((latitude_sign, ) + latitude_dms))
            text.append('%s%03i%02i' % ((longitude_sign, ) + longitude_dms))
        elif format == 'dms':
            text.append('%s%02i%02i%02i' % ((latitude_sign, ) + latitude_dms))
            text.append('%s%03i%02i%02i'
                        % ((longitude_sign, ) + longitude_dms))
    else:
        raise ValueError('Unknown format type %r' % format)
    if altitude and int(altitude) == altitude:
        text.append('%+i' % altitude)
    elif altitude:
        text.append('%+.3f' % altitude)
    text.append('/')
    return ''.join(text)