From c0758c5135bfaa66880ef624a49838c9fe8ae6b8 Mon Sep 17 00:00:00 2001 From: Kain Klob <60397874+KKlob@users.noreply.github.com> Date: Sat, 22 Oct 2022 16:21:58 -0400 Subject: [PATCH] Create palindrome_number_optimized.py --- .../palindrome_number_optimized.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Python Basic Programs/palindrome_number_optimized.py diff --git a/Python Basic Programs/palindrome_number_optimized.py b/Python Basic Programs/palindrome_number_optimized.py new file mode 100644 index 0000000..64ede09 --- /dev/null +++ b/Python Basic Programs/palindrome_number_optimized.py @@ -0,0 +1,31 @@ +## Palindrome Checker + +## Takes in a number or a string and checks if it is a palindrome +''' +>>> checkIfPalindrome("racecar") +True +>>> checkIfPalindrome(1234567890987654321) +True +>>> checkIfPalindrome(94835764385) +False + +''' + +value = str(input('Enter a string or a number: ')); + +def checkIfPalindrome(value): + i = 0 + j = len(value) - 1 + + while i < j: + if value[i] is value[j]: + i += 1 + j -= 1 + else: + print(value + " is not a palindrome") + return False + + print(value + " is a palindrome") + return True + +print(checkIfPalindrome(value))