1
h16
CS8 M17
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"

h16: Review for final

ready? assigned due points
true Wed 09/06 09:30AM Fri 09/08 03:30PM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

MAY ONLY BE TURNED IN IN THE LECTURE/LAB LISTED ABOVE AS THE DUE DATE.
There is NO MAKEUP for missed assignments, and you may not submit work in advance, or on behalf of another person.
In place of that, we drop the four lowest scores (if you have zeros, those are the four lowest scores.)


https://ucsb-cs8-m17.github.io/hwk/h16/

These problems are review for the final exam, and refer to material from Chapters 2-6, and section 7.1

  1. (10 pts) Please fill in the information at the top of this homework sheet, including your name and umail address. If the other two items apply, please fill them in as well. Please do this every single time you submit homework for this class. It is important to fill in both name and umail every time, since handwriting is sometimes difficult to decipher. Having both helps us ensure you get credit for your work.

    Also: while we strongly prefer that you submit your homework on a single sheet of paper, if you MUST submit it on multiple sheets, JUST write your name at the top of both sheets and turn in both sheets UNCONNECTED.

    DO NOT staple, paper clip, spit-fold-and-tear, or do ANYTHING that would make it difficult to automatically feed your paper through a scanner.

  2. (20 pts) Write an python function definition count_ae that takes one parameter s and returns 0 if s is not a string, otherwise returns the number of occurences of a and e in that string (only lowercase). For example:

    • count_ae(-42) should return 0
    • count_ae("Santa Ynez") should return 3
    • count_ae("Santa Ana") should return 3 (the uppercase A does not count)
  3. (10 pts) Write two test cases in the pytest style for count_ae

  4. For each of the problems below, write a python functions with the name indicated that takes one parameter called aList, or test cases for those functions (in the style of pytest). In each case, you may assume aList is of type list and that all values in aList are of type int, and that aList contains at least two elements. For these problems, you don’t need to check those things.

    Your code may not modify the list in any way. If you want to make a sorted copy of the list as a local variable, you may use this code:

       sortedCopy = aList[:].sort()
    
    1. (10 pts) minValue, which returns the minimum value in the list without using the built-in function min.

    2. (10 pts) Two test cases (in the pytest style) for minValue

    3. (10 pts) avgValue which returns the average value of the elements in the list. You may any built in functions available in Python, or compute the sum using the accumulator pattern (your choice).

    4. (10 pts) Two test cases (in the pytest style) for avgValue

    5. (10 pts) secondSmallest which computes the second smallest element in the list (not the second smallest value). For example, secondSmallest([3,7,3]) should return 3.

    6. (10 pts) Two test cases (in the pytest style) for secondSmallest