def get_input2(prompt, conditions_any=[], conditions_all=[], debug=False):
    """Return user input, after validating it against arbitrary criteria.
    
    The user input must satisfy all conditions in conditions_all, and one or
    more of the conditions in conditions_any.  Conditions_any is a list, with
    the first item the error string to display if none of the conditions are
    met.  Conditions_all is a list of tuples, with each tuple having one 
    condition + the associated error string to display to the user if the
    condition is not met.
    
    The conditions will be inserted in 'if' statements, and must be written
    so that the 'if' statement will be true if the data is valid.  E.g.
    
    if a 'Q' is needed:
    'X == "Q"'

    Note 1: all data input by the user is seen as a string, even if numbers are
    entered.  If the test is looking for an integer, write it as:
    'int(X)'
    
    Note 2: All tests are run inside 'try' statements, so exceptions will not
    cause problems.  Any test that raises an exception is treated as a failed
    test.
    
    Note 3: One idiosyncrasy of 'if' statements is that any statement that
    returns a '0' is treated as a False.  Tests must be crafted so a pass
    does not return a '0'.  E.g., if the test is intended to check that the
    data is a float, and a zero would be valid data, do not write the test as:
    'float(X)', as 'if float("O"):' will not pass.
    
    """
    input_validated = False
    while not input_validated:
        X = eval(input(prompt))
        validated_any = False
        validated_all = True
        if len(conditions_any) > 0:
            error_string = conditions_any[0]
            for condition in conditions_any[1:]:
                if debug:
                    print(('Testing condition', condition))
                try:
                    if eval(condition):
                        validated_any = True
                        if debug:
                            print(('Test of ', condition, 'passed'))
                    elif debug:
                        print(('Test of ', condition, 'failed'))
                except:
                    if debug:
                        print('Exception during test')
                    pass
        if len(conditions_all) > 0:
            for condition in conditions_all:
                if debug:
                    print(('Testing condition', condition[0]))
                try:
                    if eval(condition[0]):
                        if debug:
                            print(('Test of ', condition[0], 'passed'))
                        pass
                    else:
                        if debug:
                            print(('Test of ', condition[0], 'failed'))
                        validated_all = False
                        print(condition[1])
                except:
                    if debug:
                        print('Exception during test')
                    validated_all = False
                    print(condition[1])
        if not validated_any:
            print((error_string, '\n'))
        elif validated_all:
            input_validated = True
    return X
