Find us on Facebook

Thursday, December 13, 2018

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:

Popular Posts

Text Widget

Search This Blog

Powered by Blogger.

Blogger Pages

Like Canvas?

Sponsor

Footer Widgetized Areas

About Canvas

About Canvas

Subscribe Us

About

Text Widget

Tags

Total Pageviews

print pdf

cal

Most Popular

    TUPLES
 LIST and SLICING
      ASCII VALUE
Copyright © KTU Btech Cse Python Lab Manuals | Powered by Blogger
Design by Saeed Salam | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates