Skip to content

Instantly share code, notes, and snippets.

@dumpmycode
Created February 25, 2016 13:27
Show Gist options
  • Save dumpmycode/40acc93dee670aaabffd to your computer and use it in GitHub Desktop.
Save dumpmycode/40acc93dee670aaabffd to your computer and use it in GitHub Desktop.
practicepython.org - palindrome.py
#! /usr/bin/env python
def pali(data, word):
for index in range(data):
if word[index] != word[len(word)-(index+1)]:
print('{} is not palindrome.'.format(word))
exit(0)
print('{} is palindrome.'.format(word))
def check(word):
word = word.lower().replace(' ', '')
word = word.translate(None, "!@#$%^&*()[]{};:,./<>?\|`~-=_+")
evenhaf = len(word)/2
oddhaf = (len(word)-1)/2
if len(word) <= 3:
if word[0] == word[len(word)-1]:
print('{} is palindrome.'.format(word))
elif len(word)%2 == 0:
pali(evenhaf, word)
else:
pali(oddhaf, word)
check(raw_input("Enter some word(s) or number(s) and I'll check if it's a palindrome: "))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment