[Edu-sig] Programming Exercises

Scott David Daniels Scott.Daniels at Acm.Org
Thu May 26 19:10:31 CEST 2005


Chuck Allison wrote:
> Hello Scott,
> 
> Thursday, May 26, 2005, 1:55:15 AM, you wrote:
> 
> SDD> Chuck Allison wrote:
> 
>>>Hello edu-sig,
>>>
>>>  Does anyone know of a good source of programming exercises/projects
>>>  to use when teaching Python to people who already know another
>>>  language? Solutions don't need to be available - I just need some
>>>  good sample programming assignments. Thanks.
>>>
> 
> SDD> You need to tell us what yu are interested in / would like to do.
> SDD> Do you want to find eigenvectors? Do you want to do GUI work? ....
> 
> Good question. Mostly I need general assignments (using sequences,
> mappings, text processing, basic OO, launching processes for testing,
> etc.), but also simple mail apps and basic COM (like processing
> Microsoft Word docs). No higher math. Some basic GUI ones would be
> nice too (will be using wxPython). Thanks!
> 
> 
First, do the Python tutorial if you have not.  Try following Dive
Into Python if it meets your tastes.

For text processing:

Create or obtain a couple of plain ASCII texts.  One should be short
for testing and development, and another long for fun and production.
Look to  Project Gutenberg if you don't have anything long yourself.
Make a concordance (words to position) that you can save and restore
w/o re-counting your text.   Find the N (50 for big) most frequent
words used.

Once you have all that working, figure out how to show all instances
of a selected word "in context".  For extra credit, words, sorted by
frequency or alphabetically (button selectable) presented on a wx
window that show your "word in context" when clicking on a word.

That should hold you for a day or two.

---

My bias is to go test-forward, so (if you want to try that) here is
a start (a first test to pass).  Most of this is boilerplate, look at
the body of test_words to see the only actual test here.  Create a
test_wordy.py file as so:

     import unittest
     from StringIO import StringIO
     import wordy	# the module you are actually testing

     class TestWords(unittest.TestCase):
         def test_words(self):
             source = StringIO("a test")
             self.assertEqual(['a', 'test'], list(wordy.aswords(source)))

     if __name__ == '__main__':
         unittest.main()

Now, when you run python on this file you will get a failure.  The first
one is that wordy.py doesn't exist.  Keep fixing until your test passes.
Then add tests for new behavior, watch them fail, and fix the source
until it works.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Edu-sig mailing list