IT 116: Introduction to Scripting
Quiz 10 Answers

  1. If list_1 is a list, what is list_2 after the following statement is executed?
    list_2 = list_1
    a new list variable pointing to the same list as list_1
  2. Write a Python statement that creates a new list, list_2, that has all the elements of the list list_1 in the same order.
    list_2 = list_1[:]
  3. Can a function that is given a list as a parameter and does not have a return statement change the list given as a parameter?
    yes
  4. If list_1 and list_2 are list variables, write a Python statement that creates the new list list_3 that consists of all the elements in list_1 followed by all the elements in list_2.
    list_3 = list_1 + list_2
  5. Write a Python statement that creates a tuple assigned to the variable numbers containing the integers 1 through 5.
    numbers = (1, 2, 3, 4, 5)
  6. Write a Python statement that create an empty tuple assigned to the variable empty.
    empty = ()
  7. Write a Python statement creates a tuple containing only the integer one an assigns it to the variable t_1.
    t_1 = (1,)
  8. Does does a tuple have an append method?
    no
  9. Can you concatenate two tuples?
    yes
  10. Write the function print_2_d_list that prints out a two dimensional list with each inner list appearing on a single line.
    def print_2_d_list(list):
        for row in range(len(list)):
            row_string = ""
            for column in range(len(list[row])):
                row_string += str(list[row][column]) + " "
            print(row_string)