Compsci 06/101, Spring 2012, Lab 10

By entering your name/net-id below you indicate you are present for Lab 10 to answer these questions and that you were part of the process that resulted in answers being turned in.
Name: ______________    Net id: _____________ || Name: ______________    Net id: _____________

Name: ______________    Net id: _____________ || Name: ______________    Net id: _____________

  1. User-generated substitutions

    1. in do_mad_lib what is the purpose of this code in the function (you can remove it to see what it does)? contents = re.sub("\n", " ", contents)

    2. What about the statement above allows you to infer that re.sub does not change its argument contents, i.e., that the function re.sub returns a value but doesn't have a side-effect on its parameter?
      
      
      
    3. What is the list-comprehension you used to substitute values generated by calling get_word_from_user for each element in all_tags?
      
         subs = 
      

  2. Reading the Dictionary

    1. The read_tagstore function loops over each line that it reads, what is the purpose of calling line.strip()?
      
      
      

    2. What code creates a list of the comma-separated words that come after the colon on a line?
      
      
      
      

    3. The key in the dictionary is given by local variable key. What code did you write to add values to an already existing dictionary value (a list) corresponding to key?
      
      
      
      
  3. Word-getter Function parameter

    1. What is the list-comprehension that generates replacements for each tag in all_tags, but generates them automatically by calling get_word_from_computer?
      
      
      
      
    2. How many parameters does do_mad_lib have when you've finished this section?
      
      
      
  4. Function print_out

    1. What update did you make to curr_len if the line was too long? Why did you do this?
      
      
      
      
    2. What update to curr_len did you make when printing the word followed by a space?
      
      
      
    3. Why is the change print word, sufficient to print a word, followed by a space, and remain on the same line for the next print?
      
      
      
  5. tag-a-story category

    What is the category of the tag-a-story, Mad Lib you created?