ic02 : Review (tracing functions)
num | ready? | description | assigned | due |
---|---|---|---|---|
ic02 | true | Review (tracing functions) | Tue 09/11 09:30AM | Tue 09/11 10:50AM |
-
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
Function Call True
False
None
Python
error
messagesomething
elsehasNoX_2("Fox")
✔ hasNoX_2("Xie")
hasNoX_2("Axe")
hasNoX_2("Pat")
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.
Function Call True
False
None
Python
error
messagesomething
elsehasNoX_3("Fox")
hasNoX_3("Xie")
hasNoX_3("Axe")
hasNoX_3("Pat")
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.
Function Call True
False
None
Python
error
messagesomething
elsehasNoX_4("Fox")
hasNoX_4("Xie")
hasNoX_4("Axe")
hasNoX_4("Pat")
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.
Function Call True
False
None
Python
error
messagesomething
elsehasNoX_5("Fox")
hasNoX_5("Xie")
hasNoX_5("Axe")
hasNoX_5("Pat")
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.
Function Call True
False
None
Python
error
messagesomething
elsehasNoX_6("Fox")
hasNoX_6("Xie")
hasNoX_6("Axe")
hasNoX_6("Pat")
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