<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def read_dir(input_dir,input_ext,func):
    '''reads all files with extension input_ext
       in a directory input_dir and apply function func
       to their contents'''
    import os
    for dirpath, dnames, fnames in os.walk(input_dir):
        for fname in fnames:
            if not dirpath.endswith(os.sep):
                dirpath = dirpath + os.sep
            if fname.endswith(input_ext):
                func(read_file(dirpath + fname))