From 2b7c4854b9fcf144f6c915610218f2ac7d52618d Mon Sep 17 00:00:00 2001 From: Muhammad Umer Farooq Date: Sun, 16 Feb 2020 11:24:08 +0500 Subject: [PATCH 1/3] Create is_palindrome.py --- strings/is_palindrome.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 strings/is_palindrome.py diff --git a/strings/is_palindrome.py b/strings/is_palindrome.py new file mode 100644 index 000000000000..d8c16624012d --- /dev/null +++ b/strings/is_palindrome.py @@ -0,0 +1,16 @@ +def is_palindrome(s): + """ + Determine whether the string is palindrome + :param s: + :return: Boolean + """ + if s == s[::-1]: + return True + return False + + +s = input("Enter string to determine whether its palindrome or not: ") +if is_palindrome(s): + print("Given string is palindrome") +else: + print("Given string is not palindrome") From 2a07647eb7a98f0a2f10f1bebd85b369fbb34dd7 Mon Sep 17 00:00:00 2001 From: Muhammad Umer Farooq Date: Sun, 16 Feb 2020 13:09:41 +0500 Subject: [PATCH 2/3] Update is_palindrome.py --- strings/is_palindrome.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/strings/is_palindrome.py b/strings/is_palindrome.py index d8c16624012d..52833f8e41c5 100644 --- a/strings/is_palindrome.py +++ b/strings/is_palindrome.py @@ -4,12 +4,11 @@ def is_palindrome(s): :param s: :return: Boolean """ - if s == s[::-1]: - return True - return False + return s == s[::-1] -s = input("Enter string to determine whether its palindrome or not: ") + +s = str(input("Enter string to determine whether its palindrome or not: ").strip()) if is_palindrome(s): print("Given string is palindrome") else: From 9fc71ca7b289000cd5cce515b0c431419c1cb51b Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 18 Apr 2020 08:55:22 +0200 Subject: [PATCH 3/3] Update is_palindrome.py --- strings/is_palindrome.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/strings/is_palindrome.py b/strings/is_palindrome.py index 52833f8e41c5..3070970ca6d0 100644 --- a/strings/is_palindrome.py +++ b/strings/is_palindrome.py @@ -3,13 +3,17 @@ def is_palindrome(s): Determine whether the string is palindrome :param s: :return: Boolean + >>> is_palindrome("a man a plan a canal panama".replace(" ", "")) + True + >>> is_palindrome("Hello") + False """ return s == s[::-1] - -s = str(input("Enter string to determine whether its palindrome or not: ").strip()) -if is_palindrome(s): - print("Given string is palindrome") -else: - print("Given string is not palindrome") +if __name__ == "__main__": + s = input("Enter string to determine whether its palindrome or not: ").strip() + if is_palindrome(s): + print("Given string is palindrome") + else: + print("Given string is not palindrome")