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.
'''
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"))
Python help def palindrome_word: ''' (str) -> bool The parameter is a string consisting only of...
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...
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...
***************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++)...
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...
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 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 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...
I really need help with the code for this, in C++ please, I know there's a similar question but the answer isn't correct :[ A palindrome is a string that reads the same forwards and backwards (ignoring spaces, punctuation, and capitalization). Examples are the familiar ``If I had a hi-fi,'' the grander ``A man, a plan, a canal, Panama,'' and ``Some men interpret nine memos.'' So the goal: Design, implement, document, and test a program that reads a line of...
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 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...