{"id":98,"date":"2010-01-31T20:00:40","date_gmt":"2010-02-01T01:00:40","guid":{"rendered":"http:\/\/blog.alanporter.com\/?p=98"},"modified":"2010-01-31T20:00:40","modified_gmt":"2010-02-01T01:00:40","slug":"snakes-of-a-feather","status":"publish","type":"post","link":"https:\/\/alanporter.com\/blog\/2010\/01\/31\/snakes-of-a-feather\/","title":{"rendered":"Snakes of a feather"},"content":{"rendered":"<p>This time last year, <a href=\"\/blog\/2009-01-17\/nerds-of-a-feather\">Audrey wrote a computer program in BASIC<\/a>. \u00a0Someone had loaned us an Apple II computer, and I showed her what computers were like when I was a kid. \u00a0I wanted her to write a program, and her mother decided that printing a 10 x 10 multiplication table would be a suitable challenge. So Audrey rose to the task.<\/p>\n<p>This year, I decided to repeat the lesson with Sydney. \u00a0However, our two girls are very different in personality and interests, and so we had to choose a different approach.<\/p>\n<p>Audrey was motivated by her interest in history, and in learning how Daddy became a <strong>nerd<\/strong>. \u00a0Sydney was motivated by attaching a prize to the assignment &#8212; a &#8220;feather&#8221; on her Indian Princess vest. \u00a0This would count as one of our father-daughter &#8220;crafts&#8221;.<\/p>\n<p>I also decided that since I did not have the lead-in of the Apple II computer, I could use any language, and not just BASIC. \u00a0I went out on a limb and chose Python.<\/p>\n<p>Sydney followed along as we talked about variables and loops, but she was not nearly as engaged as Audrey had been. \u00a0In her defense, I think the idea of line numbers in BASIC is a little easier for a kid to grasp than the indented blocks of Python. \u00a0And although formatting the output is easier in Python, all of that punctuation was sure to blow a few fuses in that young mind.<\/p>\n<p>In the end, however, she produced a nice multiplication table.<\/p>\n<p>Here&#8217;s her program.<\/p>\n<pre>#!\/usr\/bin\/python\nimport sys\n\n# top line of numbers\nprint \"      \" ,\nx = 1\nwhile x &lt;= 10:\n   print \"%3d\" % (x) ,\n   x = x+1\nprint \"\"\n\n# top line of dashes\nprint \"      \" ,\nx = 1\nwhile x &lt;= 10:\n   print \"---\" ,\n   x = x+1\nprint \"\"\n\n# ten rows\ns = 1\nwhile s &lt;= 10:\n   # each row is here\n   print \"  %2d |\" % (s) ,\n   x = 1\n   while x &lt;= 10:\n      print \"%3d\" % (x*s) ,\n      x = x+1\n   print \"\"\n   s = s+1\nprint \"\"<\/pre>\n<p>And here&#8217;s what the output looks like:<\/p>\n<pre>         1   2   3   4   5   6   7   8   9  10\n       --- --- --- --- --- --- --- --- --- ---\n   1 |   1   2   3   4   5   6   7   8   9  10\n   2 |   2   4   6   8  10  12  14  16  18  20\n   3 |   3   6   9  12  15  18  21  24  27  30\n   4 |   4   8  12  16  20  24  28  32  36  40\n   5 |   5  10  15  20  25  30  35  40  45  50\n   6 |   6  12  18  24  30  36  42  48  54  60\n   7 |   7  14  21  28  35  42  49  56  63  70\n   8 |   8  16  24  32  40  48  56  64  72  80\n   9 |   9  18  27  36  45  54  63  72  81  90\n  10 |  10  20  30  40  50  60  70  80  90 100<\/pre>\n<p>Two days later, Sydney got to show her program to the girls in her Indian Princess tribe. \u00a0Needless to say, there were some raised eyebrows coming from some of the dads at that meeting.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This time last year, Audrey wrote a computer program in BASIC. \u00a0Someone had loaned us an Apple II computer, and I showed her what computers were like when I was a kid. \u00a0I wanted her to write a program, and her mother decided that printing a 10 x 10 multiplication table would be a suitable [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5],"tags":[],"class_list":["post-98","post","type-post","status-publish","format-standard","hentry","category-family","category-geek","count-0","even alt","author-alan","last"],"_links":{"self":[{"href":"https:\/\/alanporter.com\/blog\/wp-json\/wp\/v2\/posts\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alanporter.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alanporter.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alanporter.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alanporter.com\/blog\/wp-json\/wp\/v2\/comments?post=98"}],"version-history":[{"count":0,"href":"https:\/\/alanporter.com\/blog\/wp-json\/wp\/v2\/posts\/98\/revisions"}],"wp:attachment":[{"href":"https:\/\/alanporter.com\/blog\/wp-json\/wp\/v2\/media?parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alanporter.com\/blog\/wp-json\/wp\/v2\/categories?post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alanporter.com\/blog\/wp-json\/wp\/v2\/tags?post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}