Exercise 2: Exceptions

It’s astonishing how effective  you can code if you actually understand the instructions. It’s very straightforward yet a lot of people overlook these preliminary steps. Exercise 2 dealt with exceptions; creating, raising and implementing them.

Although the concept of exceptions is completely new, Exercise 2 was relatively easier than Exercise 1 (a basic review of definitions and classes; part A was to write the square root function from scratch and part B was to create Dog and Toy classes). Wait – what?  What happened is simple: Exercise 1 contained a lot of unnecessary information whereas Exercise 2 was concise and precise.

For example, Exercise 2 tells the coder exactly what to do:

  • ‘Submit a file called “e2a.py” that defines the following functions and other features.’
  • 'E2Error: an exception class that is a subclass of Exception.’

Whereas, Exercise 1, was a little more roundabout:

  • “Calculate the square root using Newton’s method. This is an iterative method: it starts with a guess at the answer and improves the guess over and over until it is ‘close enough’.”

The catch? In the real world clients will definitely be more like the former.  It is your job to interpret what they want and eliminate unnecessary information. Does the professor make ambiguous statements on purpose?  Of course not!

By comparing these two exercises, I’ve realized that because Exercise 2 contained new content, the simple instructions assures we can code the basics. And due to the fact that Exercise 1 explored old content, by making the instructions more complicated, it tests if we truly understand how to implement code.

When dealing with computer science assignments, it is definitely important to read the document carefully. Everything you need to know, the professor will include in the document. Any ambiguities can be easily clarified by going on discussion boards or asking the professor himself/ herself.

Looking back at Exercise 1, I find it was difficult because I was intimidated by the concept of Newton’s method. But after reviewing it, I can see that if you know which peices of information to ignore, the code is really easy to write.

Leave a comment