HOMEWORK ASSIGNMENT #2
Assigned Date: Tuesday, February 22, 2005
Due Date: Friday, March 4, 2005
Due Time: 3pm
Bonus Due Date: Sunday, March 13, 2005
Bonus Due Time: 11:55pm
Wednesday, March 02, 2005, 5:15PM (updated material is green)
This assignment will get you comfortable with Python.
All programs that you complete in your career as a student and as a professional developer should be fully documented. Follow the Golden Rule of Style: “A program should be as easy for a human being to read and understand as it is for a computer to execute.”  Obviously, you should comment any variable, obscure statement, block of code, method, and class you create. Your comments should express why something is being done, as opposed to how – the how is shown by the code. Here is one example of minimally documented code.
In this course, you should always include opening comments as follows:
# Author: <Your Name>
# Email: <Your email address>
# Class: CSIS 672, Section 1
# Assignment: HMWK2
# Due Date: <The assignment's due date>
# Certification of Authenticity <include one of the following>:
# I certify that this lab is entirely my own work.
# I certify that this lab is my own work, but I received
# some assistance from: <Name(s)>
# Purpose: <Provide a simple, yet complete description of the task being
# performed by this program. It may be several sentences long.>
# Input: <Provide a simple, yet complete description of the input required
# by this program.>
# Output: <Provide a simple, yet complete description of the output generated
# by this program.>
Write the following programs (1-4 adapted from ):
(Learning objectives: program structure, simple math,
Modify chaos.py so that the number of output values is provided by the user through the standard input.
(Learning objectives: math, I/O)
Write a program that accepts two coordinate points (x1, y1) and (x2, y2) and outputs their Euclidean distance. User provides four numbers, on a single line and in the given order, through the standard input.
(Learning objectives: string manipulation and
Write a program that calculates the average word length in a sentence entered by the user through the standard input.
(Learning objectives: functions and recursion)
Write a program which includes a function fib(n) to calculate the nth Fibonacci number recursively – n is provided by the user through the standard input.
(Learning objectives: classes and porting from Java)
Write a program containing a class Die (see Die.java) and main() method, which asks the user, on two separate lines, how many faces the die should have, and how many rolls of the die to output. User provides numbers through the standard input.
(Learning objectives: putting it all together and a bit
To create a Golden Tree, simply draw a line from some starting point (x, y) towards the 12 o’clock direction. Then draw a line from the ending point, 60 degrees clockwise, with length reduced by a factor equal to the golden ratio -- phi = 0.6180339887… . Then draw a similar line 60 degrees counterclockwise, and so on.
Write a program that draws a Golden Tree of level n (see exampleTkinter.py). Use recursive method drawGoldenTree(start_x, start_y, length, rotation, level). Your program should be invoked with: python GoldenTreeTk.py n, from the command line, where n is the level. It should output trace information for each recursive call (output drawGoldenTree’s arguments via ‘print’).
7. Bonus: Modify the above program to use wxPython instead of Tkinter. Store the new program in file goldenTreeWx.py.
8. Bonus: Modify the above program to use VPython instead of Tkinter. Store the new program in file goldenTreeV.py.
9. Bonus: Modify the VPython program to draw a 3D tree. (Hint: To produce a 3D image, make four recursive calls, instead of two.) Store the new program in file goldenTreeV3D.py.
You should submit the following files as individual attachments (do NOT archive), via email to firstname.lastname@example.org:
· NewChaos.py, EuclideanDistance.py, AverageWordLength.py, RecursiveFibonacci.py, DieRoll.py, GoldenTreeTk.py, and GoldenTreeTk.jpg (a screen snapshot of your program having generated a tree of level 14).
· Bonus: GoldenTreeWx.py, and GoldenTreeWx.jpg (a screen snapshot of your program having generated a tree of level 14).
· Bonus: GoldenTreeV.py, and GoldenTreeV.jpg (a screen snapshot of your program having generated a tree of level 14).
· Bonus: GoldenTreeV3D.py, and GoldenTreeV3D.jpg (a screen snapshot of your program having generated a tree of level 7).