Python: Palindrome program in Python

def palindrome_test(word):

flag_palindrome = True
if (len(word) >= 2):
for i in range(0, int(len(word) / 2)):
if (word[i] == word[len(word) – (i + 1)]):
flag_palindrome = True
continue
else:
print (“String is not palindrome”)
flag_palindrome = False
break
else:
print (“The string you provided does not have more than or 2 characters”)
flag_palindrome = False

if (flag_palindrome):
print (“String you entered is palindrome”)

str_to_test = input(‘Enter a string: ‘)
palindrome_test(str_to_test)

Advertisements

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: