Skip to content

Instantly share code, notes, and snippets.

@anthonyrisinger
Last active December 8, 2015 05:32
Show Gist options
  • Save anthonyrisinger/49ca785852630578e17e to your computer and use it in GitHub Desktop.
Save anthonyrisinger/49ca785852630578e17e to your computer and use it in GitHub Desktop.
Program I wrote with 1st grade son, started much simpler and grew to this
#!/usr/bin/python
# .
# |-- animals.py
# `-- sounds
# |-- cat.wav
# |-- cow.wav
# |-- dog.wav
# |-- oops.wav
# |-- sheep.wav
# `-- wolf.wav
import os
import sys
def say_animal_sound(animal):
animal_file = 'sounds/{}.wav'.format(animal)
animal_play = 'paplay ' + animal_file
os.system(animal_play)
letters_to_sounds = {'d': 'dog',
'c': 'cat',
'o': 'cow',
'w': 'wolf',
's': 'sheep'}
while True:
letter = sys.stdin.read(1)
# If the letter is "q", Quit the program.
if letter in ('q', ''):
break
# If the letter is "Enter" key, skip it.
if letter == '\n':
continue
# Look up the animal name from the letter
# given to us.
sound = letters_to_sounds.get(letter, 'oops')
say_animal_sound(sound)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment