1 |
ic03 |
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" |
ic03: Review for midterm-2 (tracing functions)
ready? | assigned | due | points |
---|---|---|---|
true | Mon 11/13 12:30PM | Mon 11/13 01: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.)
This is an in-class exercise. There is no make-up (instead, if you miss it, it may be one of your four dropped grades.)
-
One of the Python functions you were asked to write for one of the labs is the function
hasNoX
which was supposed to returnTrue
if the input were a string that does not containx
orX
, andFalse
in every other case (e.g. if the input was not of typestr
.For each of the following, there is an attempt at writing
hasNoX
, many of which contain bugs. Your job is to do what Python would do, i.e. indicate the output of the function call shown. Assume that it has been loaded intoidle3
and that we’ve selectedRun Module
(or pressed F5.)
Then we typed in the function call shown, and something is printed as a result.
Which of the answers shown matches what is printed? Put a check mark (✔) in the appropriate column.The first is done for you as an illustrationPts Function Call True
False
None
Python
error
messagesomething
else(example) hasNoX_2("Fox")
✔ (3 pts) hasNoX_2("Xie")
(3 pts) hasNoX_2("Axe")
(3 pts) hasNoX_2("Pat")
(3 pts) hasNoX_2(12345)
def hasNoX_2(s): if type(s)!=str: return False for c in s: if c!='x' or c!='X': return True return False
- Same instructions as previous problem. Hint: pay attention to the indentation.
Pts Function Call True
False
None
Python
error
messagesomething
else(5 pts) hasNoX_3("Fox")
(5 pts) hasNoX_3("Xie")
(5 pts) hasNoX_3("Axe")
(5 pts) hasNoX_3("Pat")
(5 pts) hasNoX_3(12345)
def hasNoX_3(s): if type(s)!=str: return False for c in s: if c=='x' or c=='X': return False return True
- Same instructions as previous problems.
Pts Function Call True
False
None
Python
error
messagesomething
else(5 pts) hasNoX_4("Fox")
(5 pts) hasNoX_4("Xie")
(5 pts) hasNoX_4("Axe")
(5 pts) hasNoX_4("Pat")
(5 pts) hasNoX_4(12345)
def hasNoX_4(s): if type(s)!=str: return False for c in s: if c!='x' and c!='X': return True else: return False
- Same instructions as previous problems. Hint:read the first three lines of the function definition carefully, and
compare with the others you've already done.
Pts Function Call True
False
None
Python
error
messagesomething
else(5 pts) hasNoX_5("Fox")
(5 pts) hasNoX_5("Xie")
(5 pts) hasNoX_5("Axe")
(5 pts) hasNoX_5("Pat")
(3 pts) hasNoX_5(12345)
def hasNoX_5(s): if s!=str: return False for c in s: if c=='x' or c=='X': return False return True
- Same instructions as previous problems.
Pts Function Call True
False
None
Python
error
messagesomething
else(3 pts) hasNoX_6("Fox")
(3 pts) hasNoX_6("Xie")
(3 pts) hasNoX_6("Axe")
(3 pts) hasNoX_6("Pat")
(3 pts) hasNoX_6(12345)
def hasNoX_6(s): if type(s)!=str: return False for c in s: if c=='x' or c=='X': return True return False