| 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
maskedPasswordthat takes one parameterpwand returns a string consisting of the first three characters contained in the variablepwfollowed 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 ofpwis less than 3 returnpwwithout any modification (YOU MAY ASSUMEpwis of typestr) -
Write three test cases (in the style of the
pytestmodule) that for the functionmaskedPasswordas 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
isValidPasswordthat takes a parameterpwand returns True if the variablepwis of typestrand 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
pytestmodule) that for the functionisValidPasswordas 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
minOfTwoListsthat takes two lists as parameters:alistandblist. The functions returns a new list where each element in the new list is the minimum of the corresponding elements inalistandblist. The function should raise aValueErrorexception with an appropriate message, if eitheralistorblistis 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.