46 exercises: 16-19

Here’s another blog of four more of the 46 exercises I have been working with 💻

In number sixteen the task was to write a program that would take an integer and a list of words, and return a list of the words that their length is longer than the integer:


The next one was similar to problem eight, in which the program recognized palindromes, only this time it had to work with sentences as well, like “Go hang a salami I’m a lasagna hog.”, “Was it a rat I saw?”, “Step on no pets”, “Sit on a potato pan, Otis”, “Lisa Bonet ate no basil”, “Satan, oscillate my metallic sonatas”, “I roamed under it as a tired nude Maori”, “Rise to vote sir”, or the exclamation “Dammit, I’m mad!”.


As you can see, I used the function string.punctuation in the string module to eliminate all punctuation from the sentence, as suggested from a friend of mine in the class. For this, I also used the replace() method to change it for an empty space (“”), as well as to eliminate spaces between words.


Number nineteen was about creating a program that would tell whether a phrase was a panagram or not:


In match = set(alphabet) & set(letters) the program is comparing the two lists and finding elements in common, which it then puts into a list. I read about that in this page:


And this is how it runs:


And the following exercise asked to write a program that generated all the verses in the popular song “99 bottles of beer” :


I’ll continue showing more of these exercises in future posts 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s