From fb5f7995176edc34f7e891c1720896c45f513414 Mon Sep 17 00:00:00 2001 From: Jeremy Gresham Date: Tue, 5 May 2015 13:33:36 -0400 Subject: [PATCH 1/3] added palidrome.py --- palindrome.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 palindrome.py diff --git a/palindrome.py b/palindrome.py new file mode 100644 index 0000000..2ae057e --- /dev/null +++ b/palindrome.py @@ -0,0 +1,20 @@ +import re +string = input("Enter your Text: ") +string = re.sub(r'[^A-Za-z]',"",string) +string = string.lower() + + +def ite(inp): + inp = inp[:] + while len(inp)>1: + if inp[0]==inp[-1]: + inp = inp[1:-1] + continue + else: + return False + return True + +if ite(string): + print("\"{}\" is a palindrome!".format(string)) +else: + print("\"{}\" is not a palindrome!".format(string)) From 4c48f3736a79c8518f6445a27d22ddcf8be67fc8 Mon Sep 17 00:00:00 2001 From: Jeremy Gresham Date: Tue, 5 May 2015 13:35:49 -0400 Subject: [PATCH 2/3] recursive palindrome.py --- palindrome.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/palindrome.py b/palindrome.py index 2ae057e..a160320 100644 --- a/palindrome.py +++ b/palindrome.py @@ -2,19 +2,26 @@ string = input("Enter your Text: ") string = re.sub(r'[^A-Za-z]',"",string) string = string.lower() - - -def ite(inp): +print(string) +def rec(inp): inp = inp[:] - while len(inp)>1: + + if len(inp)>2: if inp[0]==inp[-1]: - inp = inp[1:-1] - continue + return rec(inp[1:-1]) else: return False - return True -if ite(string): + else: + if(len(inp)==1): + return True + else: + if inp[0]==inp[-1]: + return True + else: + return False + +if rec(string): print("\"{}\" is a palindrome!".format(string)) else: print("\"{}\" is not a palindrome!".format(string)) From b688bd1bdebc1fb23c7bc0280240336e45ab3e9c Mon Sep 17 00:00:00 2001 From: Jeremy Gresham Date: Tue, 5 May 2015 15:57:08 -0400 Subject: [PATCH 3/3] Removed unnecessary logic, just returning value in palindrome.py --- palindrome.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/palindrome.py b/palindrome.py index a160320..63a3e24 100644 --- a/palindrome.py +++ b/palindrome.py @@ -16,10 +16,8 @@ def rec(inp): if(len(inp)==1): return True else: - if inp[0]==inp[-1]: - return True - else: - return False + return inp[0]==inp[-1] + if rec(string): print("\"{}\" is a palindrome!".format(string))