Assignment 1
Due: 11:00 AM on Friday, September 16, 2011
Question #1
Write and document a Python script cubestat.py which takes as
a command-line argument a textfile
and outputs the number of all non-zero integers in this file as well as
the sum, and average (rounded down) of the cubes of all numbers in
this file.
Your script must work on datafiles
cs1.dat,
cs2.dat,
cs3.dat, and
cs4.dat
to produce the output given in typescript-file
cubestat.script.
You may assume that all space/tab-separated strings in the given files
can be converted to valid integers.
Question #2
Write and document a Python script tcomp1.py which takes as
command-line arguments a master textfile, a word, and two or more comparison
textfiles and prints (1) the number of occurrences of the given word in the master
textfile and each of the comparison textfile and (2) the name of the comparison textfile
that is most similar to the master textfile relative to that word, i.e., the
comparison textfile whose count for that word is closest to the count for that
word in the master textfile.
Your script must work on datafiles
tc1.dat,
tc2.dat, and
tc3.dat
to produce the output given in typescript-file
tcomp1.script.
You may assume that each textfile has at most one million words.
Hints
You may find the various example scripts in the course notes of use.
In Q2, you may want to use abs(X) to compute the absolute value of
integer-valued variable or expression X.
Submission
Please hand in printed copies of all of your Python script files.
You must also submit these files electronically using the
submit-assignment command.
Note that each script file must have the following comment
block at the top, where the X's are replaced with the appropriate
information, followed by a docstring briefly describing the program in that
script. For instance, my script for Question #1 of this assignment would
begin with the following comment block:
#########################################################
## CS 2500 (Fall 2011), Assignment #1, Question #1 ##
## Script File Name: cubestat.py ##
## Student Name: Todd Wareham ##
## Login Name: harold ##
## MUN #: 8008765 ##
#########################################################
You do not have to develop your code on our CS departmental systems.
However, as your code will be compiled and tested on our CS departmental
systems as part of the assignment marking process,
you should ensure that your code compiles and runs correctly on at
least one of these systems.
- August 9, 1:50pm
Assignment #1 posted.
Created: August 9, 2011
Last Modified: August 9, 2011