Computer sciences and Information technology

Computer sciences and Information technology

CS 120 Project 4 – Strings and Characters

Fall 2014 – due Fri Nov 7 (revised)

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 separate functions to do the calculations. Input is from the keyboard, and output is to the screen.

1.    Basic string operations:  The main program should define the following strings (no data entry is required):
A = “Moravian College”
B = “Greyhounds”
C = your first name in mixed case
D = “Python programming is easy!”
E = “2.71828”
Perform the following string operations in the main program. Your program code should show how the resulting string was obtained. Separate functions are not needed.
(a)    Concatenate strings A and B, with a space separating the substrings.
(b)    Multiply string B times 4.
(c)    Extract the substring “hounds” from string B and convert it to uppercase.
(d)    Convert string C (your first name) to lowercase, and reverse the characters in the string?
(e)    What is the length of string D if the spaces are removed?
(f)    Pick a vowel, and count the number of times that vowel appears in the lowercase         version of string C.
(g)    Convert string E to a floating point number.
(h)    Split the words in string D and place them in a list.
Output the results for parts (a) to (h).

2.    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 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.
(a)    Free-Beer
(b)    NoLemonNoMelon
(c)    #123XYx321#
(d)    LeBron:Norbel
(e)    aibohphobia

3.    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.
(a)    list
(b)    while
(c)    True
(d)    Class
(e)    print
(f)    return

4    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 🙂

© 2020 customphdthesis.com. All Rights Reserved. | Disclaimer: for assistance purposes only. These custom papers should be used with proper reference.