<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def encode(claims, key, algorithm=ALGORITHMS.HS256, headers=None, access_token=None):
 """Encodes a claims set and returns a JWT string. JWTs are JWS signed objects with a few reserved claims. Args: claims (dict):
 A claims set to sign key (str or dict):
 The key to use for signing the claim set. Can be individual JWK or JWK set. algorithm (str, optional):
 The algorithm to use for signing the the claims. Defaults to HS256. headers (dict, optional):
 A set of headers that will be added to the default headers. Any headers that are added as additional headers will override the default headers. access_token (str, optional):
 If present, the 'at_hash' claim will be calculated and added to the claims present in the 'claims' parameter. Returns: str: The string representation of the header, claims, and signature. Raises: JWTError: If there is an error encoding the claims. Examples: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhIjoiYiJ9.jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8' """


    for time_claim in ['exp', 'iat', 'nbf']:

        # Convert datetime to a intDate value in known time-format claims
        if isinstance(claims.get(time_claim), datetime):
            claims[time_claim] = timegm(claims[time_claim].utctimetuple())

    if access_token:
        claims['at_hash'] = calculate_at_hash(access_token,
                                              ALGORITHMS.HASHES[algorithm])

    return jws.sign(claims, key, headers=headers, algorithm=algorithm)