# Valid Palindromes ```python= # Determine whether a string, s, is a valid palindrome def valid_palindrome_1(s): # Our base case: if len(s) = 0 or len(s) = 1, it's a palindrome! if len(s) <= 1: return True # Our recursive case - if the first and last letter are the same, # make a recursive call on the inner string: if s[0] == s[-1]: return valid_palindrome_1(s[1:-1]) else: return False # Determine whether a string, s, is a valid palindrome after # up to one character deletion def valid_palindrome_2(s): # Our base case: if len(s) = 0 or len(s) = 1, it's a palindrome! if len(s) <= 1: return True # Our simple recursive case - if the first and last letter are the same, make a recursive call on the inner string: if s[0] == s[-1]: return valid_palindrome_2(s[1:-1]) # Our more complicated recursive case - if the first and last are NOT the same, # we want to try deleting the first and recursing or the last and recursing else: return valid_palindrome_2(s[1:]) or valid_palindrome_2(s[0:-1]) def run_tests_1(): test_cases = [ {"input": "", "expected": True}, {"input": "z", "expected": True}, {"input": "abcdcba", "expected": True}, {"input": "ab", "expected": False}, {"input": "abazxaba", "expected": False}, ] for case in test_cases: if valid_palindrome_1(case["input"]) == case["expected"]: print(f"Test passed! Input: {case['input']} returned: {case['expected']}") else: print(f"Failed for case: {case['input']}") def run_tests_2(): test_cases = [ {"input": "", "expected": True}, {"input": "z", "expected": True}, {"input": "abcdcba", "expected": True}, {"input": "ab", "expected": True}, {"input": "abazxaba", "expected": True}, {"input": "abc", "expected": False}, {"input": "azcafaa", "expected": False}, ] for case in test_cases: if valid_palindrome_2(case["input"]) == case["expected"]: print(f"Test passed! Input: {case['input']} returned: {case['expected']}") else: print(f"Failed for case: {case['input']}") if __name__ == "__main__": run_tests_1() # run_tests_2() ```