Strings and Characters
Write Python programs to perform the following calculations involving characters and strings. Each program should be divided into a main() procedure that performs input and output, and a separate function to do the calculations. Input is from the keyboard, and output is to the screen.
1. Palindromes: The main program should input from the keyboard a single “word” consisting of letters, digits, and other symbols, and store it in a string variable W. The program should then call the non-recursive function reverseWord(W) to convert W to lower case, reverse the order of the characters in the string, and then return the resulting string. For example, if the string “Forest!” is input, the function should return “!tserof”.
The main program should then output the reversed word. If the output word is identical to the input string (ignoring case), the string is symmetric, so your program should output “Palindrome”. Compile and run your program with the following input words.
2. Python Keywords: The main program should input from the keyboard a single “word” consisting of letters and digits, and store it in a string variable W. The program should then call the function isKeyword(W) to check if W is a Python reserved word. Python words are case-sensitive, so don’t change the case of the input word.
If W is a Python keyword, then the function should return the logical value True. Otherwise, the return value should be the logical value False.
The main program should display the string message “Keyword!” when the function return value is True. Otherwise, the program should display “Not a Keyword”.
Compile and run your program with the following input words.
3 Vowel Counts: The main program should input a short string from the keyboard and store it in a variable S. The program should then call the function vowelCount(S) to count and return the number of vowels in the string. The program should then output the vowel count, along with the percent of characters that are vowels.
Compile and run your program with the following verses (English and Maori) from a popular New Zealand song. Enter one line at a time, and total the vowel counts by hand for the entire verse. Note than Polynesian languages tend to use a high percentage of vowels.
(a) English version
Now is the hour, when we must say goodbye.
Soon you’ll be sailing far across the sea.
While you’re away, oh, then, remember me.
When you return, you’ll find me waiting here.
(b) Maori version
Po atarau, E moea iho nei
E haere ana, Koe ki pamamao
Haere ra, Ka hoki mai ano
Ki i te tau, E tangi atu nei
PLACE THIS ORDER OR A SIMILAR ORDER WITH US TODAY AND GET AN AMAZING DISCOUNT 🙂