Skip to content

Instantly share code, notes, and snippets.

@sshehrozali
Created November 23, 2020 19:38
Show Gist options
  • Save sshehrozali/8d78544ecf1a8b3dd7c2cfd4ba58cf56 to your computer and use it in GitHub Desktop.
Save sshehrozali/8d78544ecf1a8b3dd7c2cfd4ba58cf56 to your computer and use it in GitHub Desktop.
Python program to check whether a text/word is Palindrome or not
# Ask for any word or text from User
text = str(input("Enter any word: "))
# Empty string to store reversed version of original
reversed_text = ""
# Iterate through each char
for i in range(1, len(text) + 1):
# Get char in reversed order (negative indexing)
char = text[-i]
# Store that char in reversed_text
reversed_text += char.lower()
# Check if string is 'Palindrome'
# If Yes
if reversed_text == text.lower():
print("Palindrome: Yes")
exit(0)
# If No
if reversed_text != text.lower():
print("Palindrome: No")
exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment