Skip to content

D is for dog

 1 min A little Python program I wrote with my first-grade son: type a letter, hear an animal.
Published

Dec 8, 2015

I wrote this little program with my son when he was in first grade. It started much simpler and grew into an animal-sound player.

He chose the animals. I found the sounds. The letters had jobs:

letters_to_sounds = {'d': 'dog',
                     'c': 'cat',
                     'o': 'cow',
                     'w': 'wolf',
                     's': 'sheep'}

The program read one character at a time. The dictionary supplied an animal name, and a small function used paplay to play the matching WAV file from a sounds directory. In a normal terminal, typing d and pressing Enter played the dog. The loop skipped the newline.

An unrecognized character got oops.wav. q or the end of input stopped the program.

The sound files aren’t in the gist. The little loop is.