Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Python Basic Programs/palindrome_number_optimized.py
Original file line number Diff line number Diff line change
@@ -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))