First Summer 2006

Wed Jun 14
Tue Jun 13
Mon Jun 12
They could be from Homework Ten, Seven, Six and Eight (Clock
).
Sun Jun 11
Here's a nice approach to default noarg constructors by John Kenny:
He read the book. Thought about what he read. And creatively found a solution.#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.xf.x)**2)+((self.yf.y)**2))**.5) y = Point() a = Point(3,0) b = Point(0,4) c = Point(1,1) print "the distance between the points",a.show(),"and",b.show(),"is:", a.dist(b) print "the distance between the default",y.show(),"and",c.show(),"is:", c.dist(y) raw_input("Press 'Enter' to exit: ")
Sat Jun 10
It is good exam practice.
Here's some help with Homework Nine:
The code above will create a square of given size, full of zeros.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], print n=int(raw_input("Enter size of matrix: ")) if n%2==1: l = magic(n) show (l) else: print "This is not a valid magic square dimension"
Here's the basic update procedure. Assume we update randomly here:
Here's how the code above runs: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:], print n=int(raw_input("Enter size of matrix: ")) if n%2==1: l = magic(n) show (l) else: print "This is not a valid magic square dimension"
Hope this helps with Homework Nine, due tomorrow.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
Below we have the code developed with Magnai Ganzorig in class on Fri:
So we're printing average word lengths per line and average word length per file.def average(line): new_line="" tokens=float(len(line.split())) for words in line.split(): new_line+=words return len(new_line)/tokens # this was the helper method text_file=open("text.txt","r") lines=text_file.readlines() print lines text_file.close() # this part gets all the data in a list text_file=open("output.txt","w") for line in lines: # element by element text_file.writeln(str(average(line))) # we apply the helper to the lines file="" 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 text_file.close() print "Program finished. Thank you."
Fri Jun 9
Thu Jun 8
This solution suggests at least four approaches to this problem.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
Here's a solution to the seventh problem on the same assignment:
As you can see I used a helper function.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
Here's the Coin
problem we developed in class:
Here's the way we started the objectoriented resizable pattern program: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 else: 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): coin.flip() print coin.report() coin.reset()
Today Homework Eight is due, review in class will be led by David and Joel.class Pattern(object): def __init__(self, size): result = [] for i in range(size): row = " *" * size result.append(row.split()) self.result = result
Wed Jun 7
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
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
Reminder that today David Gower and Joel Richardson will start the final review.# 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: ")
They will hope to act as Charlie Rose and David Brancaccio. This promises to be good.
Sun Jun 4
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
Fri Jun 2
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 "*", else: print " ", print
Thu Jun 1
Wed May 31
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
Lab notes for the day have been posted.
Mon May 29
Sun May 28
Grades for the semester are being updated (check A2017055).Date: Sun, 28 May 2006 22:58:21 0400 (EDT) From: Adrian German <dgerman@cs.indiana.edu> To: A201/A597 First Summer 2006 <dgerman@indiana.edu> Subject: A201/A597 Update (Midterm Exam, Review Sessions) Just a reminder there is a review session tomorrow night: Monday 7:159: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 email, individually, to follow tonight. ... Adrian
When the update is finished we will send a notification by email to everybody and post it here too.
Sat May 27
Both help sessions are CONFIRMED:
Monday because the building is locked:
Fri May 26
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
Reminder, Shakila's office hourse are noon1:00pm Tue, Wed, Thu in LH406.
Knock on the door and ask about Shakila or make appointment by email.
Adrian's office hours: 9:3010:30am daily or 9:00am1:00pm daily by appointment (both in LH201D).
Except today I won't be available 10:15am12:30pm.
Wed May 24
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 file.close() 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
Code developed today in class:

Mon May 22
SatSun May 2021
Fri May 19
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 thatProgram stops after the tenth number is processed.
 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.
Your program must only use two variables not more.
Assignment statements and simple numeric expressions is all you need.
Thu May 18
(run them, submit them to OnCourse).
Grades for the semester will be posted here from now on (check A2017055).
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
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
Note they contain a lab assignment (seven programs) that need to be turned in today, in OnCourse.
Mon May 15
Lab notes for this week to be posted tonight.Date: Mon, 15 May 2006 17:06:15 0400 (EDT) From: Adrian German <dgerman@cs.indiana.edu> To: A201/A597 Summer 2006 Distr. List <dgerman@indiana.edu> 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 email, 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 problemsolving 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. Sincerely, Adrian German
Please check this link for Python API info.
SatSun May 1314
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
Thu May 11
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
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
Labs will be taught by Shakila Shayan.
Notes for this class as taught in:
Office hours for Adrian, for now: daily 9:3010:30 in LH201D.
Schedule of office hours to be posted soon.