Posts

Showing posts with the label python string

Palindrome in python

Image
Palindrome in python Given a string, the program checks if the string is palindrome or not. A string is called palindrome if the reverse of the string is equal to the original string.  For example, the string 'madam' is a palindrome as the reverse of the string also forms the same word 'madam'. Meanwhile, the string 'Apple' is not a palindrome, the reverse of the string forms the word 'elppA'. Method 1 : In this method, the entire string is reversed. If the reversed string is equal to the original string then the string is said to be palindrome. Procedure : 1. Start. 2. Get the string from the user. 3. Reverse the string. 4. If the reversed string is equal to the original string, the string is palindrome. 5. Print the result. 6. End. Code : #get the string as input from the user s = str(input("Enter the string : ")) #reverse the string s1 = s[::-1] #if the given string is equal to the reversed string the string is palindrome if(s == s1): prin