Advertisement
viligen

recursion_palindrome

Jan 26th, 2022
800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | None | 0 0
  1. def palindrome(word, idx):
  2.     if idx == len(word):
  3.         return f"{word} is a palindrome"
  4.  
  5.     elif word[-idx - 1] == word[idx]:
  6.         return palindrome(word, idx + 1)
  7.  
  8.     else:
  9.         return f"{word} is not a palindrome"
  10.  
  11. print(palindrome("peter", 0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement