Assignment 1
Due: 3:00 PM on Friday, January 18, 2008
Question #1
Write and document a Python script fileop.py which takes as
command-line arguments a file of integers and a string op and
does the following:
- Print "x / y", where x is the number of integers in the file and y
is the number of non-integers in the file (op == "val").
- Print "x", where x is the smallest integer in the file
(op == "min").
- Print "x", where x is the largest integer in the file
(op == "max").
- Print "x", where x is the sum of all integers in the file
(op == "sum").
- Print "x", where x is the average of all integers in the file,
i.e., sum / float(# integers in file)
(op == "avg").
This script must produce the appropriate error message (see typescript-file
below) when either the file cannot be read or op is not a valid
operation. Your script must work on datafiles
fileop1.dat,
fileop2.dat, and
fileop3.dat
to produce the output given in typescript-file
fileop.script.
Question #2
Write and document a Python script tagfilt.py which takes as
command-line arguments an input file, an output file, and a set of one
one-word tag-strings and writes all lines in the input file that start
with one of those tag-strings to the output file.
This script must produce the appropriate error message (see typescript-file
below) when either the input file cannot be read or the output file cannot
be written. Your script must work on datafile
tagfilt.dat
to produce the output given in typescript-file
tagfilt.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.
At the top of each printout, please write your name and student number.
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.
- Jan 11, 5:25pm
Assignment #1 posted.
Created: January 11, 2008
Last Modified: January 11, 2008