<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_method(obj, func, name=None):
 """Adds an instance method to an object."""

    if name is None:
        name = func.__name__
    if sys.version_info < (3,):
        method = types.MethodType(func, obj, obj.__class__)
    else:
        method = types.MethodType(func, obj)
    setattr(obj, name, method)