Python Lesson 10 Exercises: String Things
In the following exercise, pay attention to your user interface, and be certain to test the programs rigorously. Save each program as pa10-1.py, pa10-2.py and so forth.
Exercise 1:
Write a translator that will translate a word into either "ubbi dubbi" or "pig latin". The program should give the user the choice of which language they prefer. "Ubbi Dubbi", the official code language of the Zoom TV show on PBS, places the letters "ub" before every spoken vowel in a word. See the Zoom Ubbi Dubbi site for details. In "Pig Latin", the first letter of each word is move to the end of the word and the letters "ay" are added to the end.
Example:
Input: Test, Mom, Dad
Ubbi Dubbi: Tubest, Mubom, Dubad.
Pig Latin: Esttay, ommay, adday.
Exercise 2:
Remember in grade school when you were learning how to use those keywords in a dictionary to tell whether or not a word would be on the page you had open? You don't remember that? Well, it's about time you learned. Create a program that will ask the user for two words (the keywords on the top of the dictionary page, presumably). Then, allow the user to enter a word and tell them whether it would be on that page or not. The program should work correctly whether the user capitalizes the words or not.
Example:
Keyword 1: Cap
Keyword 2: Cat
Your word: Car
"Car" is bewteen "Cap" and "Cat".
Exercise 3:
Write a "backward masking" program that will take a string of words and write it backwards. For example, if the user enters "I like bugs", the program should respond "sgub ekil I".
Exercise 4:
Write a program that will read in a line of text and print out how many times each letter occurs in the text.
Example:
Input: "Bryce Embry"
Output:
b 2
c 1
e 2
m 1
r 2
y 2
Exercise 5:
Create a "name game" program that takes the users name and then plays the "name game song" with it. The rules of the name game song are as follows:
Print name twice, then "bo", then the name with a "B" in place of the first letter. If the name starts with "B" already, just take the first letter of the name off competely.
Then print "Banana Fana F" and the name with an "F" in place of the first letter. If the name starts with "F" already, just take the first letter of the name off competely.
Then print "Fe Fi Mo" and the name with an "M" in place of the first letter. If the name starts with "M" already, just take the first letter of the name off competely.
Finish by repeating the name.
Sample Output1:
Harry Harry Bo Barry
Banana Fanna Fo Farry
Fe Fi Mo Marry
Harry
Sample Output2:
Billy Billy Bo Illy
Banana Fanna Fo Filly
Fe Fi Mo Milly
Billy
See here for a sample
Restricted access |