Comp 115 Test 3 Study Guide

Test on October 22-23 (depending on your lab section) 3:30-4:20 in lab

I tried my best to list the topics for the exam but I may have forgotten one or two. Your default assumption should be that if I covered it in class before files, it is fair game for the exam.

I will add practice problems as I find new interesting questions, so come back to this page every few days, more practice problems may have appeared.

In addition to all concepts from Test 2,

Lists

Repetition

Practice Problems

  1. Finish any lab exercises that you did not have time to complete during lab time. Remember, I added a whole page of exercise for the week of Fall break during which we did not have lab.
  2. Suppose that the assignment myList = ["fish", 3, 5.0, 1729, [7,8,9], 10, 39, 67] was just executed. What value would Python give to each of the following expressions:
    • myList[0]
    • myList[4]
    • myList[2:6]
    • myList[0:1]
    • myList[1:7:2]
    • myList[0][3]
    • myList[4][::2]
    • myList[:3:-3]
    Find a slice of the list in myList that would evaluate to the following value:
    • [3, 5.0, 1729]
    • [8,9]
    • [39]
    • "ish"
    • [10, [7,8,9], 1729]
  3. Determine what would be printed by each of the following pieces of code:
    1. Assume the user enters the number 30 while running the following:
        myList = [5, 17, 45, 30, 29, 18]
        lookFor = int(input("Enter a number: "))
        i = 0
        while i < len(myList) and myList[i] != lookFor:
            i = i + 1
        print(i)
    2. What would be printed by the program of the previous question if the user entered 19.
    3.   for i in range(5):
            print("*"*i)
    4.   for i in range(5):
            print("{0:_>5}".format("*"*i))
    5.   myList = [1,2,3,4,5]
        for i in range(len(myList)):
            if myList[i] == 4:
                myList[i] = 1729
        print(myList)
    6.   currentValue = 2
        while currentValue < 100:
            print(currentValue)
            currentValue = 2 * currentValue + 5
        print("DONE")