1 |
ic04 |
CS8 F17 |
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" |
ic04: Review for midterm-2 (pytest, loops and lists)
ready? | assigned | due | points |
---|---|---|---|
true | Mon 11/13 12:30PM | Mon 11/13 02:50PM |
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.)
Disregard the instruction above about “homework buddies” for this in-class assignment. For this assignment:
- Collaborating with your neighbor is allowed and encouraged
- Asking for help from the professor is allowed and encouraged
Those conditions will NOT be true on the final exam. This is just for practice.
-
(20 pts) Write the definition of a Python function
maskedPassword
that takes one parameterpw
and returns a string consisting of the first three characters contained in the variablepw
followed by ‘x’s instead of the remaining characters inpw
. The length of the returned value should be the same as the length of the parameter passed in. If the length ofpw
is less than 3 returnpw
without any modification (YOU MAY ASSUMEpw
is of typestr
) -
Write three test cases (in the style of the
pytest
module) that for the functionmaskedPassword
as defined above.- (5 pts) Write your one test case here:
- (5 pts) Write a second test case here:
- (5 pts) Write a third test case here:
-
(20 pts) Write the definition of a Python function
isValidPassword
that takes a parameterpw
and returns True if the variablepw
is of typestr
and is a valid password, according to the following rules: it must consist of at least 8 characters, include one of the special characters*
or#
and terminate with a numeric digit (0
-9
). -
Write three test cases (in the style of the
pytest
module) that for the functionisValidPassword
as defined above.- (5 pts) Write one test case here:
- (5 pts) Write a second test case here:
- (5 pts) Write a third test case here:
-
(30 pts) Write the definition of a Python function
minOfTwoLists
that takes two lists as parameters:alist
andblist
. The functions returns a new list where each element in the new list is the minimum of the corresponding elements inalist
andblist
. The function should raise aValueError
exception with an appropriate message, if eitheralist
orblist
is not a list or if either of them contains anything other than numbers (either int or float) or if the two lists are not of the same length.