Assignment 3
Due: 11:00 AM on Friday, October 2, 2009
Question #1
Consider the following rules specifying how a real number x can
be described relative to its closest integer i:
* x == i => "x is i"
* (i - 1/4) <= x <= (i + 1/4) => "x is approximately i"
* (i - 1/2) < x < i => "x is less than i"
* i < x < (i + 1/2) => "x is greater than i"
* x == i + 1/2 => "x is between i and i + 1"
Write and document a Python script numdesc.py which takes
as a command-line argument a file of positive real numbers (one per
line) and outputs for each real its description relative to the rules
given above.
Your script must work on datafile
numdesc1.dat
to produce the output given in typescript-file
numdesc.script.
You may assume that all given files are formatted correctly.
Question #2
Write and document a Python script index1.py which takes as
command-line arguments the names of a word-file (one word per line),
a text-file, and an index-file, and computes and outputs to the
index-file an index describing the lines on which each word in the word-file
occurs as part of some word in the text-file, where word-occurrence is
case-insensitive.
Your script must work on word-file
word1.txt and text-file
text1.txt to produce index-file
index1.txt as specified in
typescript-file
index1.script.
Hints
You may find the various example scripts in the course notes of use.
In Q2, you may find the string-methods lower() and/or upper()
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 2009), Assignment #3, Question #1 ##
## Script File Name: numdesc.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 interpreted and tested on our CS departmental
systems as part of the assignment marking process,
you should ensure that your code interprets and runs correctly on at
least one of these systems.
- September 30, 8:35am
Fixed errors in definition of "is approximately" in Question #1 of
Assignment #3.
- August 20, 10:35am
Assignment #3 posted.
Created: August 20, 2009
Last Modified: September 30, 2009