<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def pack_types(types, args, major):
 """Pack arguments according the the types list. Parameters types : list of kattypes The types of the arguments (in order). args : list of objects The arguments to format. major : integer Major version of KATCP to use when packing types """

    if len(types) > 0:
        multiple = types[-1]._multiple
    else:
        multiple = False

    if len(types) < len(args) and not multiple:
        raise ValueError("Too many arguments to pack.")

    if len(args) < len(types):
        # this passes in None for missing args
        retvals = map(lambda ktype, arg: ktype.pack(arg, major=major),
                      types, args)
    else:
        retvals = [ktype.pack(arg, major=major)
                   for ktype, arg in zip(types, args)]

    if len(args) > len(types) and multiple:
        last_ktype = types[-1]
        for arg in args[len(types):]:
            retvals.append(last_ktype.pack(arg, major=major))

    return retvals