Question

A palindrome is a word that is spelled the same forward and backward. For example, rotor...

A palindrome is a word that is spelled the same forward and backward. For example, rotor and redder are palindromes, but motor is not. Write a recursive function that takes a word (string) and check if it is palindrome or not (The function should return True if the word is palindrome otherwise it should return False). USING PYTHON

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def is_palindrome(s):
    if len(s) <= 1:
        return True
    else:
        if s[0].lower() != s[len(s) - 1]:
            return False
        else:
            return is_palindrome(s[1:-1])


print(is_palindrome('rotor'))
print(is_palindrome('redder'))
print(is_palindrome('anna'))
print(is_palindrome('hello'))
print(is_palindrome('palindrome'))

Add a comment
Know the answer?
Add Answer to:
A palindrome is a word that is spelled the same forward and backward. For example, rotor...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem 1: (Palindromes) A palindrome is a string that's spelled the same way forward and backward....

    Problem 1: (Palindromes) A palindrome is a string that's spelled the same way forward and backward. Some examples of palindromes are; radar, able was i ere i saw elba; and, if you ignore blanks, a man a plan a canal panama .Write a recursive function testPa1indrome that returns 1 if the string stored in the array is a palindrome and 0 otherwise. The function should ignore spaces and punctuation in the string. Please I need it in C program and...

  • palindrome is a string that reads the same both forward and backward. C++ For example, the...

    palindrome is a string that reads the same both forward and backward. C++ For example, the string "madam" is a palindrome. Write a program that uses a recursive function to check whether a string is a palindrome. Your program must contain a value-returning recursive function that returns true if the string is a palindrome and false otherwise. Do not use any global variables; use the appropriate parameters.

  • C Program: 6.31 (Palindromes) A palindrome is a string that's spelled the same way forward and...

    C Program: 6.31 (Palindromes) A palindrome is a string that's spelled the same way forward and backward. Some examples of palindromes are: "radar" "able was i ere i saw elba" and, if you ignore blanks: "a man a plan a canal panama" Write a recursive function testPalindrome that returns 1 if the string stored in the array is a palindrome and 0 otherwise. The function should ignore spaces and punctuation in the string. Use the function in a complete program...

  • A Palindrome is a string that is spelled the same way forward and backward (example: radar)....

    A Palindrome is a string that is spelled the same way forward and backward (example: radar). Write a Java program that asks the user to input a string and tests whether the string is a Palindrome or not. Display the message: "The string is a Palindrome" if it is, or "The string is NOT a Palindrome" if it is not. Assume that the user will enter a string without any spaces. The string can be any length. The String can...

  • Palindrome Detector A palindrome is any word, phase, or sentences that reads the same forward and...

    Palindrome Detector A palindrome is any word, phase, or sentences that reads the same forward and backward. Here are some well-know palindrome. Write a bool function that uses recursion to determine if a string arguments is a palindrome. The function should return true if the argument reads the same forward and backward. Demonstrate the function in a program

  • A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g.,...

    A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run. In this program, ask the user to input some text and print out whether or not that text is a palindrome. Create the Boolean method isPalindrome which determines if a String is a palindrome, which means it is the same forwards and backwards. It should return a boolean of whether or not it was a palindrome. Create the method reverse...

  • This is a java question A palindrome is a word or phrase that reads the same...

    This is a java question A palindrome is a word or phrase that reads the same forward and backward, ignoring blanks and punctuations, and considering uppercase and lowercase versions of the same letter to be equal. For example, the following are palindromes: warts n straw radar Able was I ere I saw Elba tacocat Write a program named Palindrome.java that will accept a file (file name) from the command argument list and decide whether each line in the file is...

  • write a loop that processes a string and returns true if the string is a palindrome...

    write a loop that processes a string and returns true if the string is a palindrome and false if it is not. A String is a palindrome if it is spelled the same forward as it is backward. For example, the words “joe”, “ age”, “pokemon”, “b”, “kayak” and “racecar” are all palindromes. C++ I wrote a sample but not compiling... #include"stdafx.h" #include<iostream> #include<string> int main() { Int x = 0; Int y= 0; string word = “racecar” x= 0;...

  • C++ Programming Palindrome Detector: A palindrome is any word, phrase, or sentence that reads the same...

    C++ Programming Palindrome Detector: A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man,a plan, a canal, Panama Desserts, I stressed Kayak Write a book function that uses recursion to determine if a string argument is a palindrome. The function should return true if the argument reads the same forward and backward. Demonstrate the function in a program, which continues to...

  • Write a function check palindrome, which takes a string x as argument and which returns True...

    Write a function check palindrome, which takes a string x as argument and which returns True if x is a palindrome, and False otherwise. A palindrome is a word that reads the same backwards as forwards (like for example “racecar”). Your function should be recursive (i.e. call itself) and proceed as follows. 1. If x is a string of length 0 or 1 return True. 2. If the rst and the last letter of x are di erent, return False....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT