String Palindrome
Aim: Implement
a program to check if a string is palindrome or not
Algorithm:
1.
Input a String
2.
Make it suitable for caseless comparison
using casefold() function
3.
Reverse the string
4.
Check if the string is equal to its
reverse then go to 5 else go to 6
5.
Print string Is a Palindrome go to step
7
6.
Print string Is Not a Palindrome
7.
Stop
Program:
# Program to check if a
string is palindrome or not
# take input from the
user
my_str = input("Enter
a string: ")
# make it suitable for
caseless comparison
my_str =
my_str.casefold()
# reverse the string
rev_str =
reversed(my_str)
# check if the string
is equal to its reverse
if list(my_str) ==
list(rev_str):
print("It is palindrome")
else:
print("It is not palindrome")
Output :
Enter a string: malayalam
It is palindrome
0 Comments:
Post a Comment