ic02 : Review (tracing functions)

num ready? description assigned due
ic02 true Review (tracing functions) Tue 09/11 09:30AM Tue 09/11 10:50AM
  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

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