Software & Finance





Python - Check whether given string is palindrome or not





 

Here is the python source code to check whether a given string is a palindrome or not by using while loop.

 

    #Python Source File   
    #mycode.py 
    #returns true if the given string a palindrome, otherwise false 
    def IsPalindrome(inpstr):     
    	count = len(inpstr)     
        palindrome = True    
        i = 0    
        while(i < count / 2 + 1):         
        	if(inpstr[i] != inpstr[count - i - 1]):             
            	palindrome = False            
                break        
             i = i + 1    
        return palindrome   
    #end of function 
    

Here is how you import and execute the code
>>>import mycode
>>> mycode.IsPalindrome("Kathir")
False
>>> mycode.IsPalindrome("madam")
True
>>>quit()