Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. # File: MacDonaldSong.py
  2. # 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".
  3. #
  4. # Name: David Lopez
  5. # EID: dbl353
  6. # Course Name: CS 303e
  7. #
  8. # Unique Number: 53215
  9. #
  10. # Date created: 2/21/11
  11. # Date last modified: 2/21/11
  12. #
  13. # Slip days used this assignment: 0
  14. # Total slip days used: 0
  15. #
  16.  
  17. def main():
  18.    
  19.     def printFirstLast():
  20.         #Prints the first and last line to OldMacDonald Song for less redundancy
  21.         print "Old MacDonald had a farm, E-I-E-I-O"
  22.        
  23.     def printMiddleVerse(animal, noise):
  24.         #prints middle verse to OldMacDonald Song
  25.         print "And on that farm, he had some %ss, E-I-E-I-O" % (animal)
  26.         print "With a %s-%s here, a %s-%s there" % (noise, noise, noise, noise)
  27.         print "Here a %s, there a %s" % (noise, noise)
  28.         print "Everywhere a %s-%s" % (noise, noise)
  29.    
  30.     def askUser(animal, noise):
  31.         #takes animal input & noise input and does a sentinel loop to see if user wants to quit.
  32.         while animal != "no":
  33.             print
  34.             printFirstLast()
  35.             printMiddleVerse(animal, noise)
  36.             printFirstLast()
  37.             print
  38.             animal = raw_input("Please enter an animal, or no to stop player: ")
  39.             if animal != "no":
  40.                 noise = raw_input("Please enter a noise: ")
  41.                
  42.     animal = raw_input("Please enter an animal, or no to stop playing: ")
  43.     if animal != "no":
  44.         noise = raw_input("Please enter a noise: ")
  45.         askUser(animal, noise)
  46.        
  47.            
  48.            
  49.        
  50.            
  51. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement