greenbeen seeks advice (24 recommended exercises)

Mike Brenner mikeb at mitre.org
Wed Jul 18 17:34:28 EDT 2001


Wyatt > Do I need to know what is taught in CompSci 101/102/etc, to be great?


The part that you need from Comp Sci 101/102 (in making a program that 
fully meets its specifications) is in the book DISCIPLINE OF PROGRAMMING
by Edsger Dijkstra. That book shows how to compute preconditions that
are required to meet a spec. It also gives quite a few good examples
of simple and complex programs to write.

However, most programmers don't write programs that meet specs. Most
programmer define greatness to be simply having fun while making money.

To be great in that sense, instead of meeting specs, write the
following Python programs (and for extra credit, do each program
twice -- once using wxPython graphics, and once using Jython.)


1. Algebra. Accept inputs from the user which are two lines
in the form 
	Y = m1 X + b1
	Y = m2 X + b2

That is, the user inputs the numbers m1, b1, m2, b2. 
The two m's are the slopes of the two lines. 
The two b's are the y-intercepts.

The python program will draw the first line in blue 
and the second line in green on a pair of axes in black.
Then a Red Cross will be placed at the intersection of the
two lines.

Write a test program that tests this for lines in various
positions, slopes, and intercepts.

Recover from the problem that parallel lines don't intersect at all.


2. TABLES. Neatly display a two dimensional table of numbers,
as well as displaying the sum of each row at the end of that row,
the end of each column at the bottom of that column, and a grand total
row sum and a grand total column sum (which should be the same). When
you recompile the program with different values in the table, the row
and column and grand total sums will change appropriately.

3. ROTATION. Display a red square, a blue square, and a green
square rotating across the page.

4. TEXT. Write a 3-line message to the screen inside a
rectangle, such that each time you compile it with a different message, the
rectangle adjusts its height and width, so it is a skootch larger than the text.

5. SIMPLE BOXES. Let box be defined as <box_ID, box_text1, box_text2,
box_text3, x, y>. Store an array of boxes. 
Display the boxes with their text at the proper (x,y) location on the
screen. 

6. SIMPLE ARROWS. Let arrow be defined as <from_box_ID, to_box_ID>. In
an applet, store and array of boxes and an array of arrows. Let the
applet display the boxes with their text at the proper (x,y) location on
the screen, and the arrows connecting the boxes neatly.

7. FINITE STATE MACHINE. Implement a Python program that reads in a 
list of states, character classes, transitions, and 
transductions (output translations), and produce a Python program that
implements them as a Finite State Transducer. (See Epstein's 
WORD PROCESSING IN GROUPS chapters 1 and 2.)

8. PYTHON SERVER PAGE. Install Apache and write a simple Python Server Page with
CGI communication.

9. ODBC. Same as (2) above, but get the data from a SQL database
via ODBC instead of from an internal array.

10. THREADS. Same as (3) above, but let each of the squares be in a 
different thread.

11. HTTP ARROWS. Same as (6) above, only get the files of arrows and boxes
from a URI via HTTP.

12. HTTP FSM. Same as (7) above, only get the states, etc. via HTTP. Also
implement an action table with code to be executed upon each transition.

13. SHOPPING BASKET. Create a set of Python Server Pages that
implement a simple Shopping Basket, permitting searching a 
database of products, put selected products into the shopping basket,
update the quantities in the shopping basket, charge credit cards
or budget allocations from a simulated bank, ship via a simulated
shipping company from a simulated warehouse, and notify
a simulated marketing department of how many widgets were sold.

14. TREE. Retrieve a tree structure from an http file and
walk the tree graphically in an applet that demonstrates recursive
tree walks, multiple class constructors, inheritance,
preconditions, mixing text and graphics, and 
generating XML from the tree structure.

15. SOCKETS. Send information back and forth between computers 
via sockets and via ftp.

16. MOUSE CLICKS. Same as (10) above, except control the motion
of each square via mouse clicks and drags.

17. THREE DIMENSIONS. Same as (16) above, except in three dimensions.

18. MOUSE ARROWS. Same as (6) above, except the mouse can 
add or delete or move boxes, add or delete or move arrows,
change the color of boxes or arrows, examine the contents of boxes, etc.

19. MERGE. Given a Master file consisting of data fields and a unique key field,
and a Detail file consisting of data fields and a non-unique key field, produce three
output files. First, the intersection consisting of the keys and data
from all records whose keys match in the Master and the Detail files.
Second, the records in the Master file that have no matching keys in Detail.
Third, the records in the Detail file that have no matching keys in Master.

20. DOM. Read an XML file into a DOM tree and process the tree, looking for all
system nodes. For each system nodes, call the required external program
to process the system node, passing the parameters correctly. Test it 
with external program that include encryption, decryption, database queries,
database updates, etc.

21. LL(1). Given an LL(1) grammar at a URI and a document at another URI,
create a recursive descent transducer from the grammer and execute that
transducer against that document, generating code for a virtual machine.

22. THREE TIER. Convert the shopping basket from (13) above into a full
three-tier system.

23. GAME. Create a multi-player multi-computer game.

24. SEMANTICS. Create a Python program that clusters ideas together in 
multi-dimensional semantical space and creates a four-dimensional visualization
of how close they are, how much they are coupled, and how much cohesion they have.
Test it on Shakespeare's Sonnets, on the Python Source Code, and on 
the TeX version of Michael Spivak's CALCULUS.


Substitutions in the assignments can be arranged with the instructor.





More information about the Python-list mailing list