1 |
ic03 |
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" |
ic03: Review (tracing functions)
ready? | assigned | due | points |
---|---|---|---|
true | Tue 09/12 09:30AM | Tue 09/12 10:50AM |
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.)
(28 pts) Please fill in the information at the top of this homework sheet, as usual. WRITE DARK, and remember, if you MUST submit it on multiple sheets, JUST write your name at the top of both sheets and turn in both sheets UNCONNECTED. No staples, paper clips, fold/tear etc or anything that would jam up the scanner.
-
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 illustration
Pts 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(3 pts) hasNoX_3("Fox")
(3 pts) hasNoX_3("Xie")
(3 pts) hasNoX_3("Axe")
(3 pts) hasNoX_3("Pat")
(3 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(3 pts) hasNoX_4("Fox")
(3 pts) hasNoX_4("Xie")
(3 pts) hasNoX_4("Axe")
(3 pts) hasNoX_4("Pat")
(3 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(3 pts) hasNoX_5("Fox")
(3 pts) hasNoX_5("Xie")
(3 pts) hasNoX_5("Axe")
(3 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