CSC 148 H1, Winter 2013

Exercise 2

Due: before noon on Friday 25 January 2013

There are two parts to this exercise. For each part, there is a single file you must submit — make sure that you read the submission instructions carefully!

We will start marking programming style!

For all of the exercises from now on, the first test will will run will be a style checker. You can run the style checker yourself: check the main Homework page to find out how.

Important general advice

BEFORE you begin coding, make sure that you understand everything in this handout. Remember that the point of these exercises is not to get a "working" program by any means necessary — it is to ensure that you understand how to write the desired code. If you succeed in writing something that works but you do not understand why, then you have failed, no matter what grade you receive!

In particular, if there is something you do not quite understand (for example, what we mean by "a function object" in Part B below), please, for your own sake, take the time to read the online textbook and the course notes and readings, do some searching on Google and ask on the course forum or during office hours to make sure you find out.


Part A

Submit a file called "e2a.py" that defines the following functions and other features.


Part B

Submit a file called "e2b.py" that imports the names defined in the module e2a and then defines a function "reporter" that takes two parameters, a function f and a value x. Note: The parameter f is a function object, not the result of a function call. In other words, when you call reporter, you must give it the name of a function as its first parameter.

Here is what reporter(f,x) does:

Your function reporter must always return normally, so it must catch all exceptions raised while it is executing and must never raise an exception itself. Note: reporter never prints anything! Also, pay attention to return strings exactly as specified above — including the capitalization, spaces (or lack thereof), etc.

You should import names from e2a using the form "from e2a import ...". You do not really need to import raiser, but you may find it helpful to have it available while you are debugging your e2b module.