Exercise 1

Calculate the mean of the numbers 2, 4, and 10.


In [ ]:

Check your answer. (Hint: it's not 5)


In [ ]:

Exercise 2

Make a list with 6 things in it, say, "Cleese", "Chapman", "Idle", "Palin", "Jones", and "Gilliam"


In [ ]:
listofsillypeople =

Add two more things, say, "Izzard" and "Booth"


In [ ]:

Retrieve the "Chapman" field from listofsillypeople.


In [ ]:

Exercise 3

Create a list called digitslist containing the strings "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", and "nine".


In [ ]:
digitslist = [   ]

Predict the output of the following command.


In [ ]:
print digitslist[8] + digitslist[5]

Exercise 4

Make a dictionary called digitsdict whose keys are the strings "zero" through "nine" and whose values are ints 0 through 9.


In [ ]:
digitsdict = {    }

Predict the output of the following command


In [ ]:
print digitsdict["nine"] + digitsdict["seven"]

How about this one?


In [ ]:
print digitsdict[digitslist[1]] + digitsdict[digitslist[2]] + digitsdict["zero"]

Exercise 5

The following snippet prints prints each line in the file data.dat. Modify it to print the length of each line instead.


In [ ]:
fh = open("data.dat")   # open file 
for line in fh:         # loop through fh one line at a time
    print line.strip()