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.)
These problems are review for the final exam, and refer to material from Chapters 2-6, and section 7.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.
-
(20 pts) Write an python function definition
count_ae
that takes one parameters
and returns 0 ifs
is not a string, otherwise returns the number of occurences ofa
ande
in that string (only lowercase). For example:count_ae(-42)
should return0
count_ae("Santa Ynez")
should return3
count_ae("Santa Ana")
should return3
(the uppercaseA
does not count)
-
(10 pts) Write two test cases in the
pytest
style forcount_ae
-
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 ofpytest
). In each case, you may assumeaList
is of typelist
and that all values inaList
are of typeint
, and thataList
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()
-
(10 pts)
minValue
, which returns the minimum value in the list without using the built-in functionmin
. -
(10 pts) Two test cases (in the
pytest
style) forminValue
-
(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). -
(10 pts) Two test cases (in the
pytest
style) foravgValue
-
(10 pts)
secondSmallest
which computes the second smallest element in the list (not the second smallest value). For example,secondSmallest([3,7,3])
should return3
. -
(10 pts) Two test cases (in the
pytest
style) forsecondSmallest
-