Exam 1 - October 14

Exam 1 will be Wed October 14 during normal class time in our same room. The exam will be written, no notes, no calculator, just pencil/pen/eraser and paper. There should be around 5 to 6 problems on the exam.

Answers

Content

The material covered will be Day 1 up to and including Day 15. Anything I mentioned in class can potentially be on the exam, and the notes for each day mostly cover what I talked about. Look back at the pages for the lectures to see all the topics, but the highlights are:

Example Problems for the exam

There will be a couple short-answer problems, where I ask you to write three to five sentences about one of the topics covered. For example,

Those are just examples, any of the topics we have covered could have questions about them. Next, there will be a problem or problems asking you to write down a few lines of python code. Since you can't run the code, I will give partial credit if your code has syntax errors. Here you want to make sure you indent enough so that I can see the code indented.

Notice that all of the above problems can be done using at most four to five lines of code and the exam problems will be similar. Finally, there might be a problem where I give you some python code and ask you to write some sentences explaining what the code is doing.

Answers

x y (x or y) (x and not(y)) (x or y) and (x and not(y))
T T T F F
T F T T T
F T T F F
F F F F F

Compute the number of nonnegative entries

def count_nonneg(L):
    c = 0
    for x in L:
        if x >= 0:
            c = c + 1
    return c

Here is the mean

def mean(L):
    total = 0.0
    for x in L:
        total = total + x
    return total/len(L)

Here is the median (this is just slightly more complicated than a function that might appear on the exam but is good practice).

def median(L):
    L.sort()
    if len(L) % 2 == 1: # odd length
        return L[len(L)/2]
    else:
        x1 = L[len(L)/2 - 1]
        x2 = L[len(L)/2]
        return (x1+x2)/2.0

Phone numbers

s = "312 996 3041"
area = s[0:3]
t = "(" + area + ")" + s[4:7] + s[8:]