Compsci 06/101, Spring 2012, Lab 3

By entering your name/net-id below you indicate you are present for Lab 3 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: _____________

Vocabulary

  1. What do you think the name of the string method is that returns the lower case version of a string?
    
    
    
    
    
  2. The function max returns the maximal value of a string as well as a list. What is max("science") and why?
    
    
    
    
    
    
    
  3. What is the value of reversed(sorted([5,4,1,2,8])) and why?
    
    
    
    
  4. What is the value of sorted(lst).index(min(lst)) for any list lst? Why? What's the value if min is replaced by max?
    
    
    
    
    
  5. Why is the value of str.endswith(str[-3:]) True?
    
    
    
    
  6. When is the value of st.upper().endswith(st) True? (Provide a specific example of when it's true and try to generalize)
    
    
    
    
    
  7. The in operator determines if its left operand occurs in its right operand and returns a boolean value. This means 'a' in 'stranger' evaluates to True. What is the value of 5 in [1,2,3,4]?
    
    
    
    
  8. Explain when the value of st[0:2] in st is False? (Provide a specific example of when it's true and try to generalize)
    
    
    
    
    
  9. Explain when the value of st[0:2]*2 in st is True? (Provide a specific example of when it's true and try to generalize)
    
    
    
    
    
  10. When is the value of lst.count(lst[0]) the same as the value of len(lst) for a list lst? (Provide a specific example of when it's true and try to generalize)
    
    
    
    
    
    
    


APT Acronym

Write a brief, English description of how to solve the APT.













  1. Complete the code statement below.
      words = 
    
    
  2. Write the for-loop here:
    
    
    
    
  3. Write loop to create the acronym:
      acro = ""
    
    
    
    
    
    
    
      return acro
    
    
    


Bagels APT

  1. Is it possible/ok to use elif in solution A?
    
    
    
    

  2. Explain why the three if statements in solution A can be replaced by the last statement, e.g., so that the only statement in the loop body is bagels = bagels + i + (i/12)
    
    
    
    
    
    
    
    
  3. Explain why solution B isn't as general as solution A?
    
    
    
    
    
  4. Explain why int isn't a good name for the variable used in the for-loop of solution B.
    
    
    
    
  5. Explain why int isn't a good name for the variable used in the for-loop of solution B.