[sf-lug] [PYCLASS] Session 3: Monday Oct 6

jim jim at well.com
Fri Oct 3 09:55:32 PDT 2008


   chapter 3 exercise 5 is vexing. 
   it looks like it should be generated by an algorithm 
that provides easy adjustment of values at the character 
level. e.g. 


# "matrix" means grid of all boxes 
determine number of boxes in the matrix 
determine horizontal and vertical dimensions of boxes 
calculate horizontal line length (box_horizontal * num_boxes) 

at start point, print "+ ' 
label: 
build boxes across loop Z times: 
   build horizontal line loop Y number of times: 
      print some number X of "- " 
      print a "+" 
   at end of line print "\n" 
   do verticals 
      print "/ " 
      build horizontal line loop Y number of times: 
         print some number X of "  " 
         print "/ " 
   at end of line print "\n" 
goto label N times to make N rows of boxes


   seems more elegant to build one box then build 
a row of boxes then build more rows of boxes below 
to fill out the matrix. but the line-oriented print 
functions seem not to allow this, at least not 
without a lot of fuss. (note the above algorithm 
builds a row of boxes, not a single box that can be 
plopped down across a row.) 

   seems similarly elegant to gather integers to 
determine box and matrix dimensions and then print 
appropriate characters as a modula of a range of 
characters in the whole matrix (e.g. 
   "+ " at (not (X % 5)), "- " at (X % 5), 
   newline at ((not (X % 15)+ 1), and repeat 
   until limit of range is reached, which 
   should place a newline at the bottom right 
   corner of the matrix). 
this could build the entire matrix from upper 
left corner to lower right corner in a single 
statement, given previous statements that provide 
data for the entire number of characters in the 
matrix (range) and the relative positions at 
which each character must be printed. 


   i tried both approaches but got bogged down in 
various syntax errors and seeming trivial behaviors 
that did not allow a perfect matrix. 
   i'm not big on making little boxes, so i've 
probably given up (i erase the guts of a program 
and then come back later and rethink and rewrite, 
so i might do that some more). 
   worse yet: chapter 4 is on graphics, which i've 
always tried to avoid. 




On Fri, 2008-10-03 at 08:45 -0700, Asheesh Laroia wrote:
> On Wed, 1 Oct 2008, Asheesh Laroia wrote:
> 
> > When will we go over chapter 3 of "Think Python"?
> 
> WHERE: The Grind Cafe in the Lower Haight
> WHAT: Introduction to programming class, chapter 3 of
> http://www.greenteapress.com/thinkpython/thinkpython.html
> WHEN: Mon Oct 6, 6 PM
> 
> Be sure to try to email me your answers to the chapter's exercises before 
> class.
> 
> See some of you then!
> 
> -- Asheesh.
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dotwice.py
Type: text/x-python
Size: 333 bytes
Desc: not available
URL: <http://linuxmafia.com/pipermail/sf-lug/attachments/20081003/c5d03719/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lennyrj.py
Type: text/x-python
Size: 275 bytes
Desc: not available
URL: <http://linuxmafia.com/pipermail/sf-lug/attachments/20081003/c5d03719/attachment-0001.py>


More information about the sf-lug mailing list