CS 61A

Structure and Interpretation of Computer Programs, Spring 2015

Instructor: John DeNero




Question | If This Not That

Define if_this_not_that, which takes a list of integers i_list, and an integer this, and for each element in i_list if the element is larger than this then print the element, otherwise print that.

def if_this_not_that(i_list, this):
    """
    >>> original_list = [1, 2, 3, 4, 5]
    >>> if_this_not_that(original_list, 3)
    that
    that
    that
    4
    5
    """
    ## YOUR CODE HERE ##
def if_this_not_that(i_list, this):
    index = 0
    while index < len(i_list):
        element = i_list[index]
        if element <= this:
            print("that")
        else:
            print(element)
        index += 1