CSIS 672
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

 

Updated:

Wednesday, March 02, 2005, 5:15PM (updated material is green)

 

Purpose:

This assignment will get you comfortable with Python. 

 

Documentation:

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.” [1] 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.>
#

 

Assignment: 

Write the following programs (1-4 adapted from [2]):

1.      (Learning objectives: program structure, simple math, I/O) 
Modify chaos.py so that the number of output values is provided by the user through the standard input.

2.      (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.

3.      (Learning objectives: string manipulation and iteration)
Write a program that calculates the average word length in a sentence entered by the user through the standard input. 

4.      (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. 

5.      (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.

6.      (Learning objectives: putting it all together and a bit of Tkinter)
 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.

 

Notes:

  1. Programming assignment grades will be based on design and style as well as correctness of result.
  2. Follow the above naming specs carefully (beware of case sensitivity).
  3. You may assume error-free input.

 

Submission: 

You should submit the following files as individual attachments (do NOT archive), via email to manaris@cs.cofc.edu: 

·        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).

 

References

  1. Cooper, D. and Clancy, M. (1985) “Oh! Pascal”, 2nd ed., W.W. Norton & Company, New York, p. 42.
  2. Zelle, J. (2004) “Python Programming: An Introduction to Computer Science”, Franklin, Beedle & Associates.