1 ic03 CS8 F17
Name:
(as it would appear on official course roster)
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)

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.)

1. One of the Python functions you were asked to write for one of the labs is the function hasNoX which was supposed to return True if the input were a string that does not contain x or X, and False in every other case (e.g. if the input was not of type str.

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 into idle3 and that we’ve selected Run 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
message
something
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

2. Same instructions as previous problem. Hint: pay attention to the indentation.
Pts Function Call True False None Python
error
message
something
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


3. Same instructions as previous problems.
Pts Function Call True False None Python
error
message
something
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


4. 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
message
something
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


5. Same instructions as previous problems.
Pts Function Call True False None Python
error
message
something
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