๐Ÿ
B.TECH I YEAR โ€ข II SEMESTER โ€ข R25

Python Programming - Lab Manual

Python Programming Laboratory โ€ข Program Solution

๐Ÿ“˜ R25 Regulation ๐ŸŽ“ I Year ๐Ÿ“š II Semester ๐Ÿ Python Programming ๐Ÿงช Lab Program
Selected Program

palindrome string

โ† All Python Programs

Aim:

☛   Write a function called palindrome that takes a string argument and returnsTrue if it is a palindrome and False otherwise. Remember that you can use the built-in function len to check the length of a string.

Solution :


PROGRAM: (palindrome_str.py)

 
def Palindrome(str):
	# Run loop from 0 to len/2
	for i in range( 0 , int (len(str) / 2)):
		if str[i] != str[len(str) - i - 1 ]:
			return False
	return True
# main function
s = input(" Enter any string to check palindrome = ")
boolean = Palindrome(s)
if (boolean):
	print( s , " is palindrome ")
else :
	print( s , " is not palindrome ")

OUTPUT:

 
Sample Output - 1:
Enter any string to check palindrome = MADAM
MADAM is palindrome

Sample Output - 2:
Enter any string to check palindrome = SIR
SIR is not palindrome



๐Ÿ’ป Run This Python Program

palindrome string
The selected Python program is loaded automatically into the editor. Edit the program, provide input if required and click Run.

The compiler is embedded using OneCompiler. Your Python program runs inside the embedded Python environment; Study Glance does not execute Python code directly on your web server.
โ† Back to Python Lab Programs ๐Ÿ“š All Lab Manuals