Question

Python Question: A palindrome is a string that reads identical forwards and backwards. Examples include abba,...

Python Question: A palindrome is a string that reads identical forwards and backwards. Examples include abba, abcba, a1b1b1a, houstonnotsuoh etc.

Your task is to write a function ispalindrome(string) that reads an input string and returns True if both of the following are true:

  1. The string is a palindrome

  2. The string has at least one letter (uppercase or lowercase)

For example: ispalindrome('racecar') should return True

PS: ispalindrome('123321') should return False

ispalindrome('racecar') should return True

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def ispalindrome(string):
    count = 0
    for i in range(len(string)):
        if string[i] != string[len(string) - i - 1]:
            return False
        if string[i].isalpha():
            count += 1
    return count > 0


# Testing the function here. ignore/remove the code below if not required
print(ispalindrome('racecar'))
print(ispalindrome('123321'))

True False Process finished with exit code @

Add a comment
Know the answer?
Add Answer to:
Python Question: A palindrome is a string that reads identical forwards and backwards. Examples include abba,...
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
  • [30 points] Question 3 A palindrome is a string that reads identical forwards and backwards Examples...

    [30 points] Question 3 A palindrome is a string that reads identical forwards and backwards Examples include abba, abcba, a1b1b1a, houstonnotsuoh etc Your task is to write a program that reads an input string prints that string, and then prints one of the following as appropriate: Is a Palindrome or Nota Palindrome I user response is input - racecar, the above program should print гacecar Is a Palindrome If user response is input = hello, the above program should print...

  • In C language: A palindrome is a string that reads the same forwards or backwards; for...

    In C language: A palindrome is a string that reads the same forwards or backwards; for example dad, mom, deed (i.e., reversing a palindrome produces the same string ). Write a recursive, bool-valued function, isPalindrome that accepts a string and returns whether the string is a palindrome.

  • A palindrome is a word or phrase that reads the same both forwards and backwards. "racecar"...

    A palindrome is a word or phrase that reads the same both forwards and backwards. "racecar" is a palindrome. So is, "a man a plan a canal, panama" if you ignore the spacing and the comma. Discovering how to automate the detection of palindromes is a good way to test your understanding of loops and strings. The file, "hw2problem5.py", contains a function called is_palindrome(), which has a single string parameter, s. If s is a palindrome, then is_palindrome() returns the...

  • python Problem 3 (Palindrome) Write a function called ispalindrome(string) that takes a string (with spaces) as...

    python Problem 3 (Palindrome) Write a function called ispalindrome(string) that takes a string (with spaces) as argument and returns True if that string (ignoring spaces) is a palindrome. A palindrome is a word or phrase that spells the same thing forwards as backwards (ignoring spaces). Your program should use a recursive process to determine the result, by comparing the first and last letters of the string, and if necessary, calling ispalindrome() on the rest of the string. Sample run: print(ispalindrome('never...

  • 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....

  • 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...

  • Fix the function so that it checks if the string is a palindrome #include <iostream> using...

    Fix the function so that it checks if the string is a palindrome #include <iostream> using namespace std; //Fix the function so that it checks if the string is a palindrome //(same forwards as backwards ex: racecar / radar) bool is_palindrome(string str, int i){ //base cases if (/* add the condition */) return false;    if (/* add the condition */) return true;    //recursive call return is_palindrome(str, i-1); } int main(){ string x; cin >> x;    if (is_palindrome(x,x.length())){...

  • A palindrome is a word, phrase, number, or other sequence of characters which reads the same...

    A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as madam or racecar. Write a recursive method in java that accepts a integer as its argument and returns true if it is palindrome, false otherwise. public class Recursion {                 public static void main(String[] args) {                                 Recursion r = new Recursion();                                 System.out.println(“Is 12321 a palindrome? “+ra.isPalindrome(12321)); //true                 }                 public Boolean isPalindrome(int num){                                 return false;...

  • A palindrome is a word or phrase that reads the same forward and backward, ignoring blanks...

    A palindrome is a word or phrase that reads the same forward and backward, ignoring blanks 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 that will accept a sequence of characters terminated by a period and will decide whether the string—without the period—is a palindrome. You may assume that the...

  • Write a program that uses the function isPalindrome given in Example 6-6 (Palindrome). Test your program...

    Write a program that uses the function isPalindrome given in Example 6-6 (Palindrome). Test your program on the following strings: madam, abba, 22, 67876, 444244, trymeuemyrt Modify the function isPalindrome of Example 6-6 so that when determining whether a string is a palindrome, cases are ignored, that is, uppercase and lowercase letters are considered the same. The isPalindrome function from Example 6-6 has been included below for your convenience. bool isPalindrome(string str) { int length = str.length(); for (int i...

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