Question

Python help def palindrome_word: ''' (str) -> bool The parameter is a string consisting only of...

Python help

def palindrome_word:

'''

(str) -> bool The parameter is a string consisting only of lowercase alphabetic letters. It may or may not be a palindrome. Return True

if and only if the parameter is a palindrome. The empty string is considered to be a palindrome.

'''

def palindrom_phrase:

'''

(str) -> bool The parameter is a string that may or may not be a palindrome. Return True if and only if the parameter is a palindrome, independent of letter case and ignoring

non-alphabetic characters. To be clear, non-alphabetic characters should be ignored (that is, treated as if they are not present), and uppercase letters should be considered to be

equal to their lowercase equivalents.

Ex. "Madam I'm Adam" is a palindrome.

'''

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def palindrome_word(word):
    """
    (str) -> bool The parameter is a string consisting only of lowercase alphabetic letters. It may or may not be a
    palindrome. Return True if and only if the parameter is a palindrome. The empty string is considered to be a
    palindrome.
    """
    reversed_string = ""
    for ch in word:
        reversed_string = ch + reversed_string
    return reversed_string == word


def palindrom_phrase(phrase):
    """
    (str) -> bool The parameter is a string that may or may not be a palindrome. Return True if and only if the
    parameter is a palindrome, independent of letter case and ignoring non-alphabetic characters. To be clear,
    non-alphabetic characters should be ignored (that is, treated as if they are not present), and uppercase letters
    should be considered to be equal to their lowercase equivalents. Ex. "Madam I'm Adam" is a palindrome.
    """
    reversed_string, modified = "", ""
    for ch in phrase:
        ch = ch.lower()
        if ch.isalpha():
            reversed_string = ch + reversed_string
            modified += ch
    return modified == reversed_string


print(palindrome_word("madam"))
print(palindrom_phrase("Madam I'm Adam"))
Add a comment
Know the answer?
Add Answer to:
Python help def palindrome_word: ''' (str) -> bool The parameter is a string consisting only of...
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
  • C programming Write the implementation for the three functions described below. The functions are called from...

    C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. a) Write a print_string function that prints the characters in a string to screen on- by-one. b) Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1...

  • Stack help. I need help with my lab assignment. Complete a method for a class named...

    Stack help. I need help with my lab assignment. Complete a method for a class named Palindrome that evaluates a string phrase to determine if the phrase is a palindrome or not. A palindrome is a sequence of characters that reads the same both forward and backward. When comparing the phrase to the same phrase with the characters in reverse order, an uppercase character is considered equivalent to the same character in lowercase, and spaces and punctuation are ignored. The...

  • ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName)...

    ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName) { cout << "Usage: " << executableName << " [-c] [-s] string ... " << endl; cout << " -c: turn on case sensitivity" << endl; cout << " -s: turn off ignoring spaces" << endl; exit(1); //prints program usage message in case no strings were found at command line } string tolower(string str) { for(unsigned int i = 0; i < str.length(); i++)...

  • For this assignment, you will create a program that tests a string to see if it...

    For this assignment, you will create a program that tests a string to see if it is a palindrome. A palindrome is a string such as “madam”, “radar”, “dad”, and “I”, that reads the same forwards and backwards. The empty string is regarded as a palindrome. Write a recursive function: bool isPalindrome(string str, int lower, int upper) that returns true if and only if the part of the string str in positions lower through upper (inclusive at both ends) is...

  • In C programming Write the implementation for the three functions described below. The functions are called...

    In C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. Write a print_string function that prints the characters in a string to screen on- by-one. Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1 if...

  • #19 with the following instructions 19. A palindrome is a string that can be read backward...

    #19 with the following instructions 19. A palindrome is a string that can be read backward and forward with the same result. For example, the following is a palindrome: Able was I ere I saw Elba. unction to test if a string is a palindrome using a stack. You can push characters in the stack one by one. When you reach the en string, you can pop the characters and form a new string. If the two strings are exactly...

  • Write a program(Python language for the following three questions), with comments, to do the following:   ...

    Write a program(Python language for the following three questions), with comments, to do the following:    Ask the user to enter an alphabetic string and assign the input to a variable str1. Print str1. Check if str1 is valid, i.e. consists of only alphabetic characters. If str1 is valid Print “<str1> is a valid string.” If the first character of str1 is uppercase, print the entire string in uppercase, with a suitable message. If the first character of str1 is...

  • I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not...

    I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not declared in this scope" in my main.cpp. Here are my codes. main.cpp #include <iostream> #include <string> #include "functions.h" using namespace std; //definition of the main function. //takes arguments from the command-line. int main(int argc, char *argv[]) { //Determine if you have enough arguments. //If not, output a usage message and exit program if (argc<2 || (argc == 2 && argv[1][0] == '-')) { //call...

  • Your program must prompt the user to enter a string. The program must then test the...

    Your program must prompt the user to enter a string. The program must then test the string entered by the user to determine whether it is a palindrome. A palindrome is a string that reads the same backwards and forwards, such as "radar", "racecar", and "able was I ere I saw elba". It is customary to ignore spaces, punctuation, and capitalization when looking for palindromes. For example, "A man, a plan, a canal. Panama!" is considered to be a palindrome....

  • In this assignment, you will be creating three static methods as described below: The method duplicate...

    In this assignment, you will be creating three static methods as described below: The method duplicate should accept one parameter of type String (named “str”). The method should return a String with every character in str repeated n times, where n is the length of str if str has an odd number of characters e.g. duplicate("Hat") should return "HHHaaattt" and n is double the length of str if str has an even number of characters E.g. duplicate("Hi") should return "HHHHiiii"....

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
ADVERTISEMENT