whether a word is palindrome or not using functions
As we all know,python is an easy to start programming language.
coding programs are the most problems given in hiring interviews.
So,lets get started basic programs.
problem:
Find out whether a given word is palindrome or not.
sample input:
madam
sample output:
palindrome
python code:
def palin(word):
if len(word)<2:
return True
if word[0]==word[-1]:
return palin(word[1:-1])
else:
return False
n=input()
result=palin(n)
if(result):
print('palindrome')
else:
print('not palindrome')
coding programs are the most problems given in hiring interviews.
So,lets get started basic programs.
problem:
Find out whether a given word is palindrome or not.
sample input:
madam
sample output:
palindrome
python code:
def palin(word):
if len(word)<2:
return True
if word[0]==word[-1]:
return palin(word[1:-1])
else:
return False
n=input()
result=palin(n)
if(result):
print('palindrome')
else:
print('not palindrome')
Comments
Post a Comment