First Summer 2006

Wed Jun 14
Please come to lecture today to receive current grade reports and to discuss the final exam.

Tue Jun 13
Practical Exam in lab today.

Mon Jun 12
To motivate everybody for the Practical Exam (tomorrow) we make the following offer:

There will be two programs on the Practical Exam.

They could be from Homework Ten, Seven, Six and Eight (Clock).

Sun Jun 11
Lecture Notes Twenty-Three (for Monday) contain Homework Eight solutions.

Here's a nice approach to default no-arg constructors by John Kenny:

#HW8,Prob 1, Point

class Point(object):

    def __init__(self,horiz=0,vert=0):
        self.x= horiz
        self.y= vert

    def show(self):
        return "("+str(self.x)+","+str(self.y)+")"

    def dist(self,f):
        return ((((self.x-f.x)**2)+((self.y-f.y)**2))**.5)

y = Point()
a = Point(3,0)
b = Point(0,4)
c = Point(1,1)

print "the distance between the points",,"and",,"is:", a.dist(b)
print "the distance between the default",,"and",,"is:", c.dist(y)

raw_input("Press 'Enter' to exit: ")
He read the book. Thought about what he read. And creatively found a solution.

Sat Jun 10
Homework Ten has been posted, is due Monday night.

It is good exam practice.

Here's some help with Homework Nine:

def magic(n):
     m = []  
     for i in range(n):
         m.append([0] * n)
     return m
def show(m):
     for i in range(len(m)):
         for j in range(len(m)):
             print m[i][j],
n=int(raw_input("Enter size of matrix: "))
if n%2==1:
     l = magic(n)
     show (l)
     print "This is not a valid magic square dimension"
The code above will create a square of given size, full of zeros.

Here's the basic update procedure. Assume we update randomly here:

import random

def magic(n):
     m = []  
     for i in range(n):
         m.append([0] * n)
     for k in range(1, n*n, 1):
         i = random.randrange(n)
         j = random.randrange(n)
         m[i][j] = k
     return m
def show(m):
     for i in range(len(m)):
         for j in range(len(m)):
             print ("   " + str(m[i][j]))[-3:],
n=int(raw_input("Enter size of matrix: "))
if n%2==1:
     l = magic(n)
     show (l)
     print "This is not a valid magic square dimension"
Here's how the code above runs:

Enter size of matrix: 5
  23  11  16   0  22
   0  20  10   0   9 
  21   0   0  13  24
   4  17   0   7   0 
  12  19   0   0  14
Hope this helps with Homework Nine, due tomorrow.

Below we have the code developed with Magnai Ganzorig in class on Fri:

def average(line):
    for words in line.split():
    return len(new_line)/tokens # this was the helper method 

print lines
text_file.close()               # this part gets all the data in a list 

for line in lines:              # element by element 
    text_file.writeln(str(average(line))) # we apply the helper to the lines

for line in lines:
    file+=line                  # turn the file (list of lines) in one long line 
text_file.writeln(str(average(file)))  # then apply the helper to the resulting string

print "Program finished. Thank you." 
So we're printing average word lengths per line and average word length per file.

Fri Jun 9
Here's Homework Nine's solution in Java.

Thu Jun 8
Here's a show-off solution to the fifth problem on Homework Seven:

def sameSet(a, b):
    for i in range(len(a)):
        if not a[i] in b:
            return False
    for elem in b:
        if not contains(a, elem):
            return False
    return True

def contains(a, elem):
    for e in a:
        if e == elem:
            return True
    return False
This solution suggests at least four approaches to this problem.

Here's a solution to the seventh problem on the same assignment:

def sameElements(a, b): # other approach sort then equals
    for e in a:
        if count(e, a) != count(e, b):
            return False
    for e in b:
        if count(e, a) != count(e, b):
            return False
    return True

def count(elem, a):
    sum = 0
    for i in a:
        if i == elem:
            sum += 1
    return sum
As you can see I used a helper function.

Here's the Coin problem we developed in class:

import random

class Coin(object):
    def __init__(self):
        self.heads = 0
        self.tails = 0
    def flip(self):
        num = random.randrange(2)
        if num == 0:
            self.tails += 1
            self.heads += 1
    def report(self):
        return "Heads: " + str(self.heads) + ", tails: " + str(self.tails);
    def reset(self):
        self.heads = 0
        self.tails = 0

coin = Coin()
for exp in range(20): 
    for i in range(1000):
Here's the way we started the object-oriented resizable pattern program:

class Pattern(object):
    def __init__(self, size):
        result = []
        for i in range(size):
            row = " *" * size
        self.result = result
Today Homework Eight is due, review in class will be led by David and Joel.

Wed Jun 7
Remaining presentations, in order:

Wednesday Thursday Friday Monday
Danny Kaufman David Gower Joel Richardson Magnai Ganzorig Preeti Misra

In addition anyone who wants to contribute is more than welcome too.

Tue Jun 6
A group of about 32 problems has been posted as Lecture Notes Eighteen (yesterday).

Lectures from now on will start with review then someone will work out problems from the list posted.

Labs will ask you to take notes in lecture and implement those notes in lab and submit them to OnCourse.

Mon Jun 5
Congratulations to John Kenny who wrote this very instructive program:

# Defined Sum Average:
x = 0
def numbers():
   newnumb = []
   userin = ""
   while userin == "":
       userin = raw_input("Enter the string of numbers\n(ex. 5 3 6 4): ")
       newnumb = userin.split()
   return newnumb

def sum(numbers,x):
   """Sums numbers entered, and counts how many entered"""
   x = 0
   total = 0
   for i in range(len(numbers)):
       total += float(numbers[i])
       x += 1
   return total,x

def average(sum):
   aver = float(sum[0])/sum[1]
   return aver

print "To get the average", average(sum(numbers(),x))," = The Average"

raw_input("Press 'Enter' to exit: ")
Reminder that today David Gower and Joel Richardson will start the final review.

They will hope to act as Charlie Rose and David Brancaccio. This promises to be good.

Sun Jun 4
Lab grades almost up to date. John Kenny wrote a nice program to be posted here soon.

Tomorrow final review starts, featuring Joel Richardson and David Gower as our exclusive analysts.

Tomorrow Chapters 1 and 2, more details to be posted soon.

Sat Jun 3
Planned power outage in Lindley occurred today, so the building was shut down.

Fri Jun 2
Here's an example of what we developed in class on Fri.

size = int(raw_input("What size: "))

for lin in range(size):
    for col in range(size):
        if lin == 0 or lin == size - 1 or col == 0 or (lin == size / 2 and col < size/2):
            print "*",
            print " ",

Thu Jun 1
Lecture Notes Sixteen (detailing Lab Assignment for the day) posted.

Wed May 31
Midterm Exam in class today (1:10-2:15pm).

Labs Eleven and Twelve, Homework Assignments Seven and Eight to be posted today.

Grades for the exam to be posted Thu morning in Postem.

Tue May 30
Our help session is in LH102 at 7:15pm.

Lab notes for the day have been posted.

Mon May 29
Our help session is in LH102 at 7:15pm.

Sun May 28
Reminder sent to the distribution list just now, for tomorrow:

Date: Sun, 28 May 2006 22:58:21 -0400 (EDT)
From: Adrian German <>
To: A201/A597 First Summer 2006 <>
Subject: A201/A597 Update (Midterm Exam, Review Sessions)

Just a reminder there is a review session tomorrow night:

      Monday 7:15-9:15pm in LH102 (lecture room)

and also one on Tuesday, same time, same place.

Homework Six is due tomorrow at the end of the day and the
exam is on Wednesday in class, during lecture.

Solutions for all the problems not on Homework Six have been
posted Saturday evening under Lecture Notes Fourteen. If you
have any questions please let me know.

Tomorrow the building is locked, so I will be at the back door
around 7:05pm to start admitting people for the review session,
hope to see everyone who needs help there.

Gradebook has been updated, complete set of grades plus grade
reports sent by e-mail, individually, to follow tonight.

... Adrian
Grades for the semester are being updated (check A201-7055).

When the update is finished we will send a notification by e-mail to everybody and post it here too.

Sat May 27
All solutions for the exam that can be posted have been posted in Lecture Notes Fourteen.

Both help sessions are CONFIRMED:

Monday because the building is locked:

Fri May 26
Semester grading update: Instead of make-ups we'll just

Midterm Exam preparations:

Here's the polynomial solution to the months problem discussed in class with John Ullman.

Based on your minute papers I think it would be best to schedule two help/review sessions:

I will try to confirm these as soon as possible (and find out the status of LH on Monday).

Thu May 25
Grade reports delayed one more day but assignment six has been posted.

Reminder, Shakila's office hourse are noon-1:00pm Tue, Wed, Thu in LH406.

Knock on the door and ask about Shakila or make appointment by e-mail.

Adrian's office hours: 9:30-10:30am daily or 9:00am-1:00pm daily by appointment (both in LH201D).

Except today I won't be available 10:15am-12:30pm.

Wed May 24
Homework Six will be posted tonight, lecture notes for tomorrow will start the midterm review.

Sally Wood will be our guest today.

Program that Sally will be developing for us:

def tokens(line):
    tokens = line.split()
    return len(tokens)

def nonspace(line):
    tokens = line.split()
    sum = 0
    for token in tokens:
        sum = sum + len(token)
    return sum

file = open("C:/Documents and Settings/dgerman/Desktop/rem.txt", "r")
bob = ""
jim = ""
tom = ""
for line in file:
    if len(line) > len(bob):
        bob = line
    if tokens(line) > tokens(jim):
        jim = line
    if nonspace(line) > nonspace(tom):
        tom = line

print bob
print jim
print tom

A good test file for this program would be (note all the spaces):

I've watched the stars fall silent from your eyes
All the sights that I have seen
I can't believe that I believed I wished
T h a t  y o u  c o u l d  s e e 
There's a new planet in the solar system
There is nothing up my sleeve

                      I'm pushing an elephant up the stairs
I'm tossing up punch lines that were never there
Over my shoulder a piano falls
Crashing to the ground

Tue May 23
Homework Five is now complete, due Thursday at the end of the day.

Code developed today in class:
  • problem 3 assignment 4 solved by Joel Richardson
  • problem 4 assignment 4 solved by Preeti Misra
  • jumpstart for the lab assignment for today
have just been posted under Lecture Notes Eleven.

Mon May 22
Topics for labs this week posted, lab notes to follow, including lab assignments.

Sat-Sun May 20-21
Chapters 6, 7 and 8 from Alice are summarized in notes posted at the end of this week.

Fri May 19
Here's the program we wrote in class today:

i = 0

word = raw_input("Enter: ")

while word != "done":
    i = i + 1
    print i
    word = raw_input("Enter: ")

print "Thank you for using this program"

Here's an alternative statement for problem 3 on the first homework assignment:

(Averages) Write a program that
  • asks the user to enter 10 (ten) numbers,
  • one number per line
  • and prints back (after every line)
  • the current average of all the numbers entered up to that point.
Program stops after the tenth number is processed.

Your program must only use two variables not more.

Assignment statements and simple numeric expressions is all you need.

Thu May 18
Code for the

(run them, submit them to OnCourse).

Grades for the semester will be posted here from now on (check A201-7055).

Code developed with Nick Quagliara in class yesterday is now posted as part of Lecture Notes Six.

The lecture today will be a review and overview of the problems discussed this week in lecture and lab.

The lab will be a collection of notes setting you up for the weeks ahead.

Your lab assignment for today May 18 will be posted before lecture and discussed in class too.

Wed May 17
Lab Assignment for the day posted, under Lab Notes Five.

Today in class we will discuss branching, paths and conditional execution statements in Python.

Homework Assignments Three and Four are now complete with examples and sample runs.

Tue May 16
Lab Notes Four (for today) have been posted.

Note they contain a lab assignment (seven programs) that need to be turned in today, in OnCourse.

Mon May 15
Message sent to the distribution list today:
Date: Mon, 15 May 2006 17:06:15 -0400 (EDT)
From: Adrian German <>
To: A201/A597 Summer 2006 Distr. List <>
Subject: A201/A597 update 

Dear A201/A597 Friends,

Just a reminder Homework One is due tonight. Homework Two is due
tomorrow. Please try to keep up with the due dates and should you
encounter any problems please let us know by e-mail, or in person
during office hours and we will promptly try to help.

With the labs this week we're going to start focusing exclusively
on Python. It would be good to try to install Python from the CD that
comes with the text on your machines, and to experiment with it while
looking through chapters 1, 2 and 3 of the Python book for tomorrow.

We will continue to refer to Alice, and will finish reviewing the
entire Alice textbook in class, but that would be for illustration
purposes only. The true problem-solving emphasis of the course will
however switch to the Python book in labs and gradually in lectures
as well (this week the lectures will be half and half).

Lab Notes for the week will be posted tonight, as will be the next
two new homework assignments. If you need any help or have questions
please let us know and we will try to help immediately.

Adrian German
Lab notes for this week to be posted tonight.

Please check this link for Python API info.

Sat-Sun May 13-14
Lecture Notes for Monday posted; What's Due? updated with reading assignments.

Here are three worlds we might need on Monday:

Don't forget to stay current with the reading assignments for the week.

Fri May 12
Notes for today posted.

Thu May 11
Assignments One and Two have been posted, please use the lab to get started.

Today in lab you will also be given a brief taste of Python.

We would just like to see how it compares in general with Alice (in terms of programs one can write, interface, program development etc.)

Wed May 10
There is a dropbox for today's lab assignment in OnCourse now (please use A201-7055).

Grading guidelines for this course.

Calendar for this summer session sketched on the class notes page.

Lecture Notes Two posted, provide a review of the main example in Chapter Two.

Tue May 9
First summer session starts, here's information about our class.

Labs will be taught by Shakila Shayan.

Notes for this class as taught in:

Office hours for Adrian, for now: daily 9:30-10:30 in LH201D.

Schedule of office hours to be posted soon.

Updated by Adrian German for A201/A597