Assignment 1
Due: 11:00 AM on Friday, September 18, 2009
Question #1
Write and document a Python script stats0.py which takes as
a command-line argument the name of a file of integers (zero or more
integers per line)
and outputs the number, minimum, and maximum of all
integers in the specified file.
Your script must work on datafiles
sfa.dat,
sfb.dat,
sfc.dat, and
sfd.dat
to produce the output given in typescript-file
stats0.script.
You may assume that all space/tab-separated strings in the given files
can be converted to valid integers and that all integers are in the range
-1000 to 1000 inclusive.
Question #2
Given that Imperial and Metric units are still used in different
countries, it is often necessary to convert from a measure in one unit
to a measure in another, e.g.,
- Given x feet, to convert to metres, multiply x by 0.305;
- Given x metres, to convert to feet, multiply x by 3.28;
- Given x pounds, to convert to kilos, multiply x by 0.454; and
- Given x kilos, to convert to pounds, multiply x by 2.202.
Write and document a Python script convert.py which takes as
command-line arguments a given-unit type in {feet, metres, pounds,
kilos} and an input file of non-negative real numbers (with zero or
more real numbers per line), and outputs (1) for each number, the converted
version of that number from the given unit-type to its "opposite"
unit-type, and, at the end, (2) the total number
of conversions done.
Your script must work on datafile
conv1.dat
to produce the output given in typescript-file
convert.script.
You may assume that all given unit-types are valid and all
tab-/space-separated numbers in a given file are valid real numbers or
integers.
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 2009), Assignment #1, Question #1 ##
## Script File Name: stats0.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.
- Sept 14, 9:55am
Error found and fixed in stats0.script answers for Question #1.
- Sept 3, 8:50am
Simplified Question #1 of Assignment #1.
- June 15, 2:20pm
Assignment #1 posted.
Created: June 15, 2009
Last Modified: September 14, 2009