def get_input(prompt, type, error_string, check_list=[], default='', **kwds):
    """
    Return user input after validating it.
    """
    input_validated = False
    if type == 'float':
        while not input_validated:
            input_data = eval(input(prompt))
            try:
                input_data = float(input_data)
                input_validated = True
            except ValueError:
                print(error_string)
    if type == 'float+':
        input_data = eval(input(prompt))
        try:
            input_data = float(input_data)
            if input_data < 0:
                print(error_string)
            else:
                input_validated = True
        except ValueError:
            print(error_string)
    elif type == 'float_or_blank':
        while not input_validated:
            input_data = eval(input(prompt))
            if input_data == '':
                input_data = default
                input_validated = True
            else:
                try:
                    input_data = float(input_data)
                    input_validated = True
                except ValueError:
                    print(error_string)
    elif type == 'float_str_or_blank':
        while not input_validated:
            input_data = eval(input(prompt))
            if input_data == '':
                input_data = default
                input_validated = True
            elif input_data in kwds['str_list']:
                input_validated = True
            else:
                try:
                    input_data = float(input_data)
                    input_validated = True
                except ValueError:
                    print(error_string)
    elif type == 'float+_or_blank':
        while not input_validated:
            input_data = eval(input(prompt))
            if input_data == '':
                input_data = default
                input_validated = True
                return input_data
            try:
                input_data = float(input_data)
                if input_data < 0:
                    print(error_string)
                else:
                    input_validated = True
            except ValueError:
                print(error_string)
    if type == 'int':
        while 1:
            input_data = eval(input(prompt))
            try:
                input_data = int(input_data)
                break
            except ValueError:
                print(error_string)
    if type == 'int_or_str':
        while 1:
            input_data = eval(input(prompt))
            if input_data in kwds['str_list']:
                break
            try:
                input_data = int(input_data)
                try:
                    if input_data < kwds['min']:
                        print(('You must enter an integer no less than',
                            kwds['min']))
                except KeyError:
                    pass
                try:
                    if input_data > kwds['max']:
                        print(('You must enter an integer less than', kwds[
                            'max']))
                except KeyError:
                    break
            except ValueError:
                print('You must enter an integer')
    elif type == 'list':
        while not input_validated:
            input_data = eval(input(prompt))
            if input_data == '':
                input_data = default
                input_validated = True
                return default
            if input_data in check_list:
                input_validated = True
            else:
                print(error_string)
    return input_data
