First Summer 2008


Tue Jun 10
Sample list of questions from Chris Haynes' A201/A597 (taught during the fall and spring semesters).

Mon Jun 09
Script with available times for individual appointments.

These are the port assignments for Apache installations:

Aaron Scheidler,    ascheidl
Derek Cheung,       cheungc    58100
Paul Meyer,         pammeyer   58101
Ben Kipfer,         bkipfer    58102
Cody DeSmith,       coadesmi   58103
Eric Brown,         erwbrown   58104
Charles Burd,       crburd     58105

Daniel Oates,       danoates   58106
JungHwa Kim,        jhk3       58107
Fred Wanjera,       fwanjera   58108
Chris Nichols,      nichols8   58109
Tyler Andrews,      tyandrew   58110
Wes Voirol,         wvoirol    58111
Zach Williams,      zaawilli   58112

Jason Quinley,      jquinley   58113
Richard Pinapati,   rspinapa   58114
Vivek Krishnakumar, vivkrish   58115
Ivy Wu,             yiiwu      58116
Andy DeLuce,        deluce     58117
Thu Jun 05
Here are the programs we developed in lab yesterday: Nim, Craps.

Lecture and lab notes for the day posted.

Today we will address: GUIs, files, object oriented programming (user defined types) again.

Wed Jun 04
Stages developed in class today: one, two (for the game of Nim).

I am going to mention this problem today:

[...] write a program that reads results of games (between 
a set of players) from a file and then prints the standings based on these results. Here's 
an example; suppose the players play chess. In chess you get 1 point for a win, 0 for loss, 
and 0.5 points for a tie.

The file might contain results like this:

Barkley - Jordan 0-1
Bird - Johnson :tie:

Barkley - Johnson 1-0
Bird - Jordan :tie:

Jordan - Johnson :tie:
Bird - Barkley 1-0

You could have more players. The standings would be printed as follows:

           P W T L 
1. Bird    3 1 2 0 2 points
2. Jordan  3 1 2 0 2 points
3. Barkley 3 1 0 2 1 point
4. Johnson 3 0 2 1 1 point

P means played, W means won, T means tied, L means lost. The order must
be determined as follows: most points comes first; if tied at points most
number of won games; if tied at that too, alphabetically by name. Assume
in your file all players have played the same number of games but think
what you would do if some games are postponed, as far as the sorting goes.

You have complete freedom on specifying the file format as long as it helps your user. 

Fri May 30
Midterm Exam in class today, as discussed.

Problems to prepare for the practical exam:

For the practical you will get TWO or THREE of these problems, randomly distributed.

We'll have more details posted, and we will discuss this in class Mon and Tue.

Lab assignments for 05/28 and 05/29 will be revisited Wednesday next week in lab before moving forward.

Thu May 29
Message sent to the distribution list today.

Mon-Wed May 26-28
Code we wrote in class on Wednesday:
# simulate the wandering of an intoxicated person in the plane 

import random

def rollDice():
    a = random.randrange(0, 3) - 1
    b = random.randrange(0, 3) - 1
    return a, b

drunkard = (0, 0)

for i in range(10000):
    # print "The drunkard is at", drunkard
    (dx, dy) = rollDice()
    # print "The change is with", (dx, dy)
    drunkard = (drunkard[0] + dx, drunkard[1] + dy)

print "At the end of the program drunkard is at", drunkard

# using the movement of a pen to draw a scalable pattern in a matrix of spaces 

def generate(size):
    m = []
    for i in range(size):
        row = []
        for j in range(size):
            row.append(' ')
        m.append(row)
    return m

def show(mat):
    for row in mat:
        for elem in row:
            print elem,
        print

def main():
    size = int(raw_input("Size: "))
    a = generate(size)
    show(a) # this is the empty matrix
    print "-" * 50
    pen = (0, 0)
    for i in range(size):
        a[pen[0]][pen[1]] = '*'
        pen = (pen[0], pen[1]+1)
    show(a) # having drawn the north border
    print "-" * 50
    pen = (size-1, 0)
    for i in range(size):
        a[pen[0]][pen[1]] = '*'
        pen = (pen[0], pen[1]+1)
    show(a) # having drawn the south border
    print "-" * 50
    pen = (0, size-1)
    for i in range(size):
        a[pen[0]][pen[1]] = '*'
        pen = (pen[0]+1, pen[1]-1)
    show(a) # having drawn the south border
    print "-" * 50

main()

# doing the same thing the way of lab 05/15

def pattern(size):
    for i in range(size):
        for j in range(size):
            if i == 0 or i == size-1 or i+j == size-1 or \
               i == size/2 and size/4 <= j <= 3*size/4:
                print "*",
            else:
                print " ",
        print

def main():
    size = int(raw_input("Size: "))
    pattern(size)

main()

Sun May 25
Back to the future:

I hope to post all these tonight.

Sat May 24
Code written in class yesterday: sharing data between two methods.

Fri May 23
Code written in class yesterday: minute paper leading into dictionaries; files.

Thu May 22
def dog():
    print """

                         , 
                    ,.  | \ 
                   |: \ ; :\ 
                   :' ;\| ::\ 
                    \ : | `::\ 
                    _)  |   `:`. 
                  ,' , `.    ;: ; 
                ,' ;:  ;"'  ,:: |_ 
               /,   ` .    ;::: |:`-.__ 
            _,' _o\  ,::.`:' ;  ;   . ' 
        _,-'           `:.          ;""\, 
     ,-'                     ,:         `-;, 
     \,                       ;:           ;--._ 
      `.______,-,----._     ,' ;:        ,/ ,  ,` 
             / /,-';'  \     ; `:      ,'/,::.::: 
           ,',;-'-'_,--;    ;   :.   ,',',;:::::: 
          ( /___,-'     `.     ;::,,'o/  ,::::::: 
           `'             )    ;:,'o /  ;"-   -:: 
                          \__ _,'o ,'         ,:: 
                             ) `--'       ,..:::: 
          -hrr-              ; `.        ,::::::: 
                              ;  ``::.    :::::::

    """

for visitor in [0, 1, 2]:
    print "visitor is now:", visitor
    dog()

def dogs(num):
    for visitor in num:
        dog()
Wed May 21
Last sorting method from lecture today:
def sort(a):
    b = []
    while a:
        b.append(min(a))
        a.remove(min(a))
    return b
Also here's the sequence of examples and tests we started with.

Programs we developed in lab yesterday:

sentence = "this is a test"
i = 0 # index in string 
for letter in sentence: # for every letter
    if letter in "aeiou": # if it's a vowel 
        sentence = sentence[:i] + "egg" + sentence[i:] # split and insert "egg"
        i = i + 3 # take the inserted "egg" into account!
    i = i + 1 # update index
print sentence
The vending machine:
print "Welcome to the Vending Machine!"
balance = 0
line = raw_input("coins> ")
while line != "bye":
    coins = line.split()
    for coin in coins:
        if coin == "dime":
            balance = balance + 10
        elif coin == "nickel":
            balance = balance + 5
        elif coin == "quarter":
            balance = balance + 25
        elif coin == "cent":
            balance = balance + 1
        elif coin == "dollar":
            balance = balance + 100
        else:
            print "I don't understand", coin
        print "Balance becomes: " + ("%.2f" % (balance / 100.0))
    line = raw_input("coins> ")
print "Thanks for using this program."

Tue May 20
There is a practice exam in lab today (click the Lab 7 link when the lab starts).

Homework Four, due on Thu, has been posted.

Lecture and lab notes for the entire week will be posted tonight.

Mon May 19
Last minute help with Homework Three.

Concrete details about limitations of finite representation as discussed Friday.

The example above refers to base 2 mostly (and a bit base 10, as an analogy).

The answer to the minute paper of Friday:

def fun(word, letter, dashes):
    result = ""
    for i in range(len(word)):
        if letter == word[i]:
            result += letter
        else:
            result += dashes[i]
    return result 

import random

words = ["four", "three", "two", "one", "six", "nine"]

word = words[random.randrange(0, len(words))]
print word
dashes = "-" * len(word)
print dashes

while dashes != word:
    letter = raw_input("Guess a letter:")
    dashes = fun(word, letter, dashes)
    print dashes
Nice point brought up by Derek Cham Lun Cheung: compare
h = int(raw_input("Hour:"))
m = int(raw_input("Minute:"))

if h < 10:
    hours = "0" + str(h)
else:
    hours = str(h)
if m < 10:
    minutes = "0" + str(m)
else:
    minutes = str(m)
print hours + ":" + minutes

for i in range(10):
    m = m + 1
    if m == 60:
        h = h + 1
        if h == 24:
            h = 0
        m = 0
    if h < 10:
        hours = "0" + str(h)
    else:
        hours = str(h)
    if m < 10:
        minutes = "0" + str(m)
    else:
        minutes = str(m)
    print hours + ":" + minutes
with
def show(num):
    if num < 10:
        return "0" + str(num)
    else:
        return str(num)

h = int(raw_input("Hour:"))
m = int(raw_input("Minute:"))

print show(h) + ":" + show(m)

for i in range(10):
    m = m + 1
    if m == 60:
        h = h + 1
        if h == 24:
            h = 0
        m = 0
    print show(h) + ":" + show(m)
Comparing the two, do you see the simplification brought by show?

Sat-Sun May 17-18
Outcome of discussing numerical instability in standard arithmetic operations:
http://docs.python.org/lib/decimal-tutorial.html

http://docs.python.org/lib/module-decimal.html
Basic example:
>>> import decimal
>>> 4.35 * 100
434.99999999999994
>>> decimal.Decimal(str(4.35 * 100))
Decimal("435.0")
>>> 0.1 * 10
1.0
>>> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.99999999999999989
>>> 0.1
0.10000000000000001

>>> decimal.Decimal(str(0.1))
Decimal("0.1")
>>> decimal.Decimal(str(0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1))
Decimal("1.0")
>>> for i in range(10):
	a += decimal.Decimal("0.1")
	
>>> a
Decimal("1.0")
>>>

Fri May 16
Thanks to Aaron Scheidler and Chuck Burd for essentially bringing this up:
print "Prepare to be amazed!"

initial=10000
interest=6
withdraw=50.0
month=((float(interest)/100)/12)+1

print "I am comparing", initial * month - initial, "with", withdraw

print "Are they equal? The answer is: ",
print initial * month - initial == withdraw

#-----What do you think?
We'll have more to say about this in class today.

Thu May 15
Code from class to be finished in lab:
import random

words = ["four", "three", "two", "one", "six", "nine"]

word = words[random.randrange(0, len(words))]
print word
dashes = "-" * len(word)
print dashes

while dashes != word:
    letter = raw_input("Guess a letter:")

    if letter in word:
        for c in word:
            if c == letter:
                print "(" + letter + ")",
            else:
                print c,

Tue-Wed May 13-14
Lecture and lab notes for Wednesday, Homework Three posted.

Mon May 12
Lecture notes for today, tomorrow, lab assignment for tomorrow posted now.

Individual blogs activated, we will start posting grades in them tonight.

They already contain minute paper information to date.

Sat-Sun May 10-11
List of blogs available here (still under a bit of development).

Class notes page has been redesigned, it contains link to Homework 2 (posted now).

Fri May 9
Today in class we will use this list of practice questions.

Update of website postponed for tonight.

Up to date individual feedback on lab assignments promptly sent by e-mail within 12 hours for each of the first two lab assignments (last night and the night before) as promised. Please let me know if you have any questions, concerns or need any help. Office hours, as announced in class, are daily between 10am and noon, in LH201D, or by appointment.

Thu May 8
For those who want to read ahead: chapter 3 in Dawson is what we'll do next.

Website to be updated today, all homework assignments, detailed syllabus to be posted.

Reading assignments for the rest of the summer session:

Week of May 06     Dawson chapters 1, 2
Week of May 12     Dawson chapters 3, 4
Week of May 19     Dawson chapters 5, 6
Week of May 27     Dawson chapter 7 and review
Week of Jun 02     Dawson chapter 8, 9
Week of Jun 09     Dawson chapter 10 and final review

Chapters 7, 9 and 10 won't be covered in their entirety, just selections.

Wed May 7
Lecture notes for today posted: one, two.

Reading assignment for the week is: Dawson, pp. 1-50 (first two chapters).

Syllabus and materials for the rest of the semester to be posted later today.

Here's the syllabus from last summer (we'll function in a similar way).

Tue May 6
Class starts.

Link to Books24x7 (search for Python for the absolute beginner).

Getting started with Alice: one, two.


Updated by Adrian German for A201/A597