Craft 2

Beautiful Code
Ka-Ping Yee

Make sure you understand the material in Explore 2 before you do this assignment.

Remember to choose all the names of your functions and variables well. Every time you submit an assignment, i want to see the most beautiful code you've ever written in your life. If you've never programmed before, i guess this would be easy. If you've programmed lots, then it might be hard. Let me be moved to tears by the elegance of your programs, the utter clarity of your variable names, the simplicity of your algorithms. Make me feel an irrepressible compulsion to take your work to the Louvre and beg the curator to have it preserved there.

This is a multi-part assignment. (Oh no!)

Part Un

Is there anything you're having trouble with right now? What would you prefer to have done differently in this course?

Part Deux

Turn your factorizer program into a factorizing function. The function should take an integer as an argument and return a list of the prime factors.

The result of this should be just a function (not a script). After that's done, modify your main program to use this function. When you run it all together, the behaviour should be the same as before.

You will probably find the join() method on strings very helpful. Here's how it works:

>>> zigong = ['3', '5', '7']
>>> glue = ' * '
>>> glue.join(zigong)
'3 * 5 * 7'
>>>

Part Trois

Design a module called speling that will provide functions for checking spelling. The general idea is that there will be a spelling dictionary on the disk, and we will want to use this module to check individual words or chunks of text against the dictionary. We also need to be able to tell what counts as a word, and sometimes we will also want to update the dictionary by adding or removing words. Think about what you would need to make an effective spelling checker.

Do not write the code – just decide what functions you would put in the module, and what you would call them. Don't worry about issues like the file format and algorithms in the dictionary; just look at what the module should provide for another programmer who will use it. Choose the functions so that someone using this module could easily do spelling checks even without any knowledge of the dictionary or how the module works internally. Your result should be a bunch of function definitions with no bodies, like this:

def trampoline():
    """Cause the computer to bounce off the desk."""
    pass

Each of these definitions should specify exactly what the function will do and what the arguments are for. Be precise, but don't write a novel.

Part Quatre

How much time did you spend on this homework? How about last week's homework?


This page will let you submit the assignment. Once you log in at the top of the page, you'll see a submit button right here: .

You can submit the parts of the assignment separately if you like. Just leave parts of the form blank, and they will be ignored. You can also come back and re-submit parts if you want. I'll look at the most recent submission for each part.

This assignment is due at 6 pm on Monday 3 February. You get a bonus if it's correct and submitted at least 24 hours early.