Created
November 23, 2020 19:38
-
-
Save sshehrozali/8d78544ecf1a8b3dd7c2cfd4ba58cf56 to your computer and use it in GitHub Desktop.
Python program to check whether a text/word is Palindrome or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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