To get us started, let’s consider the children’s song “Apples and Bananas,” wherein we intone our favorite fruits to consume:
I like to eat, eat, eat apples and bananas
Subsequent verses substitute the main vowel sound in the fruits for various other vowel sounds, such as the long “a” sound (as in “hay”):
I like to ate, ate, ate ay-ples and ba-nay-nays
I like to eat, eat, eat ee-ples and bee-nee-nees
And so forth. In this exercise, we’ll write a Python program called apples.py that takes some text, given as a single positional argument, and replaces all the vowels in the text with the given -v
or --vowel
options (with the default being a
).
The program should be written in the 08_apples_and_bananas directory and should handle text on the command line:
$ ./apples.py foo faa
$ ./apples.py foo -v i fii
$ ./apples.py -v i "APPLES AND BANANAS" IPPLIS IND BININIS