Assignment 1
Due: 11:00 AM on Friday, September 17, 2010
Question #1
Write and document a Python script sumfiles.py which takes as
a command-line argument the name of a single-column file of filenames (one
filename per line)
and outputs the number, sum, and average (rounded down) of all positive
non-zero integers in the specified files.
Your script must work on datafiles
sf1.dat,
sf2.dat,
sf3.dat,
sf4.dat,
sfa.dat,
sfb.dat,
sfc.dat, and
sfd.dat
to produce the output given in typescript-file
sumfiles.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 wlo.py which takes as
command-line arguments an input file and a list of one or more keywords and
for each keyword, prints each line in which that word occurs along with the
number of that line in the file. If a particular keyword does not occur in
any line in the file, a message is printed.
Your script must work on datafile
wlo.dat
to produce the output given in typescript-file
wlo.script.
Hints
You may find the various example scripts in the course notes of use.
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 2010), Assignment #1, Question #1 ##
## Script File Name: sumfiles.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.
- Sep 2, 11:50am
Assignment #1 posted.
Created: September 1, 2010
Last Modified: September 2, 2010