Compsci 101, Fall 2014, Lab 4

Answer the following questions on the online google form for lab 4.

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)
    
    
    
    
    
    
    

Reasoning about Conditionals

  1. For each of the following three choices, state if the higher fee is assigned to the higher speed and if not explain why.

    Example A:
    
    
    Example B:
    
    
    Example C:
    
    
    

  2. Which expression was equivalent (A, B, C, D, or E):
    
    
    
  3. Which of the following implementations of a method is_leap returns true if year is a leap year and false otherwise. For each one list whether or not it is correct. If a method is not correct, provide a value for year for which it returns the wrong value.
    FIRST ONE:
    
     
     
    SECOND ONE:
    
    
    
    THIRD ONE:
    
    
    
    

  4. Complete the function all_same below.
    def all_same (value1, value2, value3):
    
    
    
    
    
    

APT ScoreIt

  1. Value returned by call maxPoints([2,2,4,5,4]) and why?
    
    
    
    
    
  2. Expression for number of 2's in the list toss?
    
    
    
    
    
  3. Why elif won't work with an example:
    
    
    
    
    
    
    
    
    
    
  4. What is the loop for generalizing the code from the previous part?