M.Sc Python Programming Assignments
Assignment 8
Question:
To check whether a number is palindrome or not. (using recursion and without recursion).
Code:
def is_palindrome_recursive(word):
if len(word) <= 1:
return True
elif word[0] != word[-1]:
return False
else:
return is_palindrome_recursive(word[1:-1])
word = input("Enter a word: ")
if is_palindrome_recursive(word):
print(f"{word} is a palindrome.")
else:
print(f"{word} is not a palindrome.")
Output:
Enter a word: India
India is not a palindrome.