CSCI 470
Assigned Date: Friday, September 3, 2004
Due Date: Monday, September 13, 2004
Due Time: 3pm


Updated: Wednesday, September 8, 2004, 4:26 PM.



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.” [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.

In this course, you should always include opening comments as follows:   

#   Author:     <Your Name>
#   Email:      <Your email address> 
#   Class:      CSCI 470, Section 1 
#   Assignment: HMWK1
#   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 [2]):

1.      (Learning objectives: program structure, simple math, I/O) 
Modify 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 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 and main() method, which asks the user how many faces the die should have, and how many rolls of the die to output.  User provides two 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 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  Use recursive method drawGoldenTree(start_x, start_y, length, rotation, level).  Your program should be invoked with:  python 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’).



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



You should submit your source file on a floppy disk, as per syllabus instructions. 

Source filenames to be submitted:  A directory named <firstName_lastName_fourLastDigitsofSSN>_hmwk1 (for example, Bill_Manaris_2308_hmwk1).  This directory should contain the following files:

·,,,,, and


  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.