Python String Assignments
For this series of assignments, refer to the Strings reference page for assistance.
Prompt for a string to be entered from the keyboard, then print the string to the screen, one character per line.
Save as "string1.py".
Enter a word: test
Prompt for a multi-word string to be entered from the keyboard, then print the string to the screen, one word per line.
Save as "string2a.py".
Enter some words: this is a sentence
Initialize a string to "abc def\tghi\njkl", then print the string to the screen, one "word" per line. Notice that this string contains a space, a tab, and a newline character to separate the words.
When writing this program, use the string.whitespace constant to compare to the characters to determine when to print on the next line.
Save as "string2b.py".
Amend the previous assignment to use the split() method to put the words into a list before printing them to the screen. (Again, one word per line.)
Isn't that much simpler than the previous methods? Can you see any potential problems using this method?
Save as "string2c.py".
Also using the split() method used in the previous program, write a program that reads in a text file from disk and prints out the total number of words in the file.
Save as "string2d.py".
There are 77986 words in Frankenstein.txt
Write a program that continuously prompts for a string to be entered from the keyboard until one of "y", "yes", "oui", "n", "no", or "non" (in lower or upper case) is entered, then outputs "You entered 'yes'" or "You entered 'no'", as appropriate.
For this assignment, use a list containing each of the test cases, as follows:
yesNo = ["y", "yes", "oui", "n", "no", "non"]
Your program should loop through each of the test cases to determine if one of those cases was chosen.
Hint: You'll find lower() very useful here!
Save as "string3.py".
Prompt for a string to be entered from the keyboard, then print a count of the usage of each A-Z character (disregarding case) to the screen. Do not print the count of any characters that are not present in the string (use string.ascii_uppercase to achieve this.
Save as "string4.py".
As in the previous assignment, print a count of all A-Z characters (again, disregarding case), but this time include other characters such as "!@#$%", etc. Do not print the count of any characters that are not present in the string.
Save as "string5.py".
Write a program that continuously prompts for words to be entered from the keyboard until "end" is entered in either upper or lower case. The program should then print back all words to the screen, on one line.
Save as "string6.py".
Write a program that continuously prompts for words to be entered from the keyboard until "end" is entered in either upper or lower case. For each word entered, print "word is a palindrome" if it is a palindrome, otherwise print "word is not a palindrome". Be sure to disregard case.
Save as "string7a.py"
Rewrite your palindrome program so this time it is searching for palindromes in a text file. Again, start with Mary Shelley's Frankenstein, and then try some others from Project Gutenburg. Record each palindrome in a list, then report the palindromes and the number of times each occurs.
Save as "string7b.py".
Save as "string7b_2.py".
Google Doc URL: https://goo.gl/CfqHdX