Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # File: MacDonaldSong.py
- # Description: A program asking the user to enter a series of animal names and sounds and print the corresponding verses from the song "Old MacDonald had a farm". The program quits when the user enters "no".
- #
- # Name: David Lopez
- # EID: dbl353
- # Course Name: CS 303e
- #
- # Unique Number: 53215
- #
- # Date created: 2/21/11
- # Date last modified: 2/21/11
- #
- # Slip days used this assignment: 0
- # Total slip days used: 0
- #
- def main():
- def printFirstLast():
- #Prints the first and last line to OldMacDonald Song for less redundancy
- print "Old MacDonald had a farm, E-I-E-I-O"
- def printMiddleVerse(animal, noise):
- #prints middle verse to OldMacDonald Song
- print "And on that farm, he had some %ss, E-I-E-I-O" % (animal)
- print "With a %s-%s here, a %s-%s there" % (noise, noise, noise, noise)
- print "Here a %s, there a %s" % (noise, noise)
- print "Everywhere a %s-%s" % (noise, noise)
- def askUser(animal, noise):
- #takes animal input & noise input and does a sentinel loop to see if user wants to quit.
- while animal != "no":
- print
- printFirstLast()
- printMiddleVerse(animal, noise)
- printFirstLast()
- print
- animal = raw_input("Please enter an animal, or no to stop player: ")
- if animal != "no":
- noise = raw_input("Please enter a noise: ")
- animal = raw_input("Please enter an animal, or no to stop playing: ")
- if animal != "no":
- noise = raw_input("Please enter a noise: ")
- askUser(animal, noise)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement