<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/rss-style.xsl" type="text/xsl"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	     xmlns:dc="http://purl.org/dc/elements/1.1/"
	   xmlns:atom="http://www.w3.org/2005/Atom"
	     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	  xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>Python Pals &#8211; Terence Eden’s Blog</title>
	<atom:link href="https://shkspr.mobi/blog/tag/python-pals/feed/" rel="self" type="application/rss+xml" />
	<link>https://shkspr.mobi/blog</link>
	<description>Regular nonsense about tech and its effects 🙃</description>
	<lastBuildDate>Sun, 03 Nov 2024 08:48:49 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://shkspr.mobi/blog/wp-content/uploads/2023/07/cropped-avatar-32x32.jpeg</url>
	<title>Python Pals &#8211; Terence Eden’s Blog</title>
	<link>https://shkspr.mobi/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title><![CDATA[Wanted! Simple APIs Without Authentication]]></title>
		<link>https://shkspr.mobi/blog/2014/04/wanted-simple-apis-without-authentication/</link>
					<comments>https://shkspr.mobi/blog/2014/04/wanted-simple-apis-without-authentication/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Mon, 07 Apr 2014 11:02:53 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[Python Pals]]></category>
		<guid isPermaLink="false">http://shkspr.mobi/blog/?p=9614</guid>

					<description><![CDATA[As some of you may know, I&#039;m writing a series of short stories to help young people learn how to code.  One of the things I wanted to do was introduce the concept of using RESTful APIs.  It&#039;s so powerful to show people that they can retrieve information from the Internet and then manipulate it in software.  Originally, I had wanted to use Twitter and Flickr as examples - they&#039;re both fairly well…]]></description>
										<content:encoded><![CDATA[<p>As some of you may know, I'm writing <a href="https://github.com/edent/PythonPals">a series of short stories to help young people learn how to code</a>.</p>

<p>One of the things I wanted to do was introduce the concept of using RESTful APIs.  It's so powerful to show people that they can retrieve information from the Internet and then manipulate it in software.</p>

<p>Originally, I had wanted to use Twitter and Flickr as examples - they're both fairly well known and have interesting content.  The only problem is that both <strong>require</strong> authentication.  I'm an adult with two decades of programming experience and I <em>still</em> find OAuth-dances tricky!  I've no idea how to create a foolproof guide for a child to get authentication tokens.  Added to the fact that under-13 year-olds often can't legally enter into agreements with these companies.</p>

<p>So, after <a href="https://twitter.com/edent/status/426271643980546048">posting the question on Twitter</a>, I've decided to make a list of fun and useful APIs which can be accessed without any form of authentication.</p>

<h2 id="wikipedia"><a href="https://shkspr.mobi/blog/2014/04/wanted-simple-apis-without-authentication/#wikipedia">Wikipedia</a></h2>

<blockquote class="social-embed" id="social-embed-426273875178307584" lang="es" itemscope="" itemtype="https://schema.org/SocialMediaPosting"><blockquote class="social-embed" id="social-embed-426271643980546048" lang="en" itemscope="" itemtype="https://schema.org/SocialMediaPosting"><header class="social-embed-header" itemprop="author" itemscope="" itemtype="https://schema.org/Person"><a href="https://twitter.com/edent" class="social-embed-user" itemprop="url"><img class="social-embed-avatar social-embed-avatar-circle" src="data:image/webp;base64,UklGRkgBAABXRUJQVlA4IDwBAACQCACdASowADAAPrVQn0ynJCKiJyto4BaJaQAIIsx4Au9dhDqVA1i1RoRTO7nbdyy03nM5FhvV62goUj37tuxqpfpPeTBZvrJ78w0qAAD+/hVyFHvYXIrMCjny0z7wqsB9/QE08xls/AQdXJFX0adG9lISsm6kV96J5FINBFXzHwfzMCr4N6r3z5/Aa/wfEoVGX3H976she3jyS8RqJv7Jw7bOxoTSPlu4gNbfXYZ9TnbdQ0MNnMObyaRQLIu556jIj03zfJrVgqRM8GPwRoWb1M9AfzFe6Mtg13uEIqrTHmiuBpH+bTVB5EEQ3uby0C//XOAPJOFv4QV8RZDPQd517Khyba8Jlr97j2kIBJD9K3mbOHSHiQDasj6Y3forATbIg4QZHxWnCeqqMkVYfUAivuL0L/68mMnagAAA" alt="" itemprop="image"><div class="social-embed-user-names"><p class="social-embed-user-names-name" itemprop="name">Terence Eden is on Mastodon</p>@edent</div></a><img class="social-embed-logo" alt="Twitter" src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%0Aaria-label%3D%22Twitter%22%20role%3D%22img%22%0AviewBox%3D%220%200%20512%20512%22%3E%3Cpath%0Ad%3D%22m0%200H512V512H0%22%0Afill%3D%22%23fff%22%2F%3E%3Cpath%20fill%3D%22%231d9bf0%22%20d%3D%22m458%20140q-23%2010-45%2012%2025-15%2034-43-24%2014-50%2019a79%2079%200%2000-135%2072q-101-7-163-83a80%2080%200%200024%20106q-17%200-36-10s-3%2062%2064%2079q-19%205-36%201s15%2053%2074%2055q-50%2040-117%2033a224%20224%200%2000346-200q23-16%2040-41%22%2F%3E%3C%2Fsvg%3E"></header><section class="social-embed-text" itemprop="articleBody">What's an interesting / popular API which does NOT require authentication / API key?<br>Trying to inspire new coders without terrifying them!</section><hr class="social-embed-hr"><footer class="social-embed-footer"><a href="https://twitter.com/edent/status/426271643980546048"><span aria-label="2 likes" class="social-embed-meta">❤️ 2</span><span aria-label="0 replies" class="social-embed-meta">💬 0</span><span aria-label="1 reposts" class="social-embed-meta">🔁 1</span><time datetime="2014-01-23T08:34:14.000Z" itemprop="datePublished">08:34 - Thu 23 January 2014</time></a></footer></blockquote><header class="social-embed-header" itemprop="author" itemscope="" itemtype="https://schema.org/Person"><a href="https://twitter.com/invisiblecomma" class="social-embed-user" itemprop="url"><img class="social-embed-avatar social-embed-avatar-circle" src="data:image/webp;base64,UklGRooCAABXRUJQVlA4IH4CAABwDACdASowADAAPq1EmEmmI6IhNVgNUMAViWoAqSbiMb2PxbRmnuD40w5eWlpTWg00xs/0ti/OME7rYyhkvgdPEFG7gh/T+BhQeAvPjE98IvaUCdE6ayEDMcus0OBYKv5S+LaeOZ71l5up/aAA/vtoCp/t6e1PPYLXt63NDZIpKR5lniwDv4MxUNVQ1604iWUXk4kRL8JFxOn6n37+CWgyhtPhSNyVwKIRJupPynn/hHtjFNdPXpm33ntI0v3fKLsZCTShGY3YPlbw0Iv0P80ScgdB3Fx4hAq7os0y2syP3YW3c454NPmtOH3p/y8Hgw8NbvUbxGXKSNzj1Mk82+/zCllPP7rQVp5s0XJ1CoaAXb3XEaO0wHHqe8XSKRXlOVAnUvk2Eyghohbguh8NI11S6CXMohgMuc65sNp20JfdUkcT8ywBBNfzCvmlezyXQekjl9hrehrOFeKgdKkCZj3RCm7ky0sI2W9i9yFdZ69TDw/EeNaJma0OoTUb9qXb2oceqokiRvPbO7xnc5l2CzbGUwGgL+0A9L0AJ4DoWnBn4MNU7mM82XlUuQS1BJT31uQVAe2nXyC58jhYghB7DCsI/vZYVkcfWurbxSqKUsoMbWRXLv7qbDy9KcxU1nSxwMOYT4TeDusQR4kvkKBqcTZkrftf5IZVFL9+k4MKeZQeALvRobhEoeRUCtNQMw65s39mf4Aoe2eU9+kGNHbrV4kMXWCmSGXNfIB4+xpz08dQWbWpFWgrt0VO2m5reCeK5HWip+EMbZ7nMT7SfjvJC99AdbiHIv2m3Ub18u8/RTpag9LdcLwBogVCJOQGH1lnFiySlDjUVuWzdWwJ3AAAAA==" alt="" itemprop="image"><div class="social-embed-user-names"><p class="social-embed-user-names-name" itemprop="name">Alf Eaton</p>@invisiblecomma</div></a><img class="social-embed-logo" alt="Twitter" src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%0Aaria-label%3D%22Twitter%22%20role%3D%22img%22%0AviewBox%3D%220%200%20512%20512%22%3E%3Cpath%0Ad%3D%22m0%200H512V512H0%22%0Afill%3D%22%23fff%22%2F%3E%3Cpath%20fill%3D%22%231d9bf0%22%20d%3D%22m458%20140q-23%2010-45%2012%2025-15%2034-43-24%2014-50%2019a79%2079%200%2000-135%2072q-101-7-163-83a80%2080%200%200024%20106q-17%200-36-10s-3%2062%2064%2079q-19%205-36%201s15%2053%2074%2055q-50%2040-117%2033a224%20224%200%2000346-200q23-16%2040-41%22%2F%3E%3C%2Fsvg%3E"></header><section class="social-embed-text" itemprop="articleBody"><small class="social-embed-reply"><a href="https://twitter.com/edent/status/426271643980546048">Replying to @edent</a></small><a href="https://twitter.com/edent">@edent</a> Wikipedia?</section><hr class="social-embed-hr"><footer class="social-embed-footer"><a href="https://twitter.com/invisiblecomma/status/426273875178307584"><span aria-label="2 likes" class="social-embed-meta">❤️ 2</span><span aria-label="1 replies" class="social-embed-meta">💬 1</span><span aria-label="0 reposts" class="social-embed-meta">🔁 0</span><time datetime="2014-01-23T08:43:06.000Z" itemprop="datePublished">08:43 - Thu 23 January 2014</time></a></footer></blockquote>

<p>Why didn't I think of this first!?  The <a href="http://en.wikipedia.org/w/api.php?">Wikipedia API is self documenting</a> - although a little intense for a first time programmer.  It will also <a href="https://en.wikipedia.org/w/api.php?action=query&amp;titles=Albert_Einstein&amp;prop=images">pretty-print the information in a browser</a> - which makes it much more readable to a novice.</p>

<h2 id="radio-1"><a href="https://shkspr.mobi/blog/2014/04/wanted-simple-apis-without-authentication/#radio-1">Radio 1</a></h2>

<p>The BBC offers a <a href="http://www.bbc.co.uk/radio1/developers/api/">bunch of developer APIs for Radio 1</a>.</p>

<p>Sadly, lots of the data returned is out of date, or simply broken. It is possible to get the latest Radio 1 playlist</p>

<pre>http://www.bbc.co.uk/radio1/playlist.json
</pre>

<p>But it's not wonderfully informative and links to XML documents if you want to actually play MP3 snippets.</p>

<h2 id="police-uk"><a href="https://shkspr.mobi/blog/2014/04/wanted-simple-apis-without-authentication/#police-uk">Police UK</a></h2>

<blockquote class="social-embed" id="social-embed-426278057846919169" lang="en" itemscope="" itemtype="https://schema.org/SocialMediaPosting"><header class="social-embed-header" itemprop="author" itemscope="" itemtype="https://schema.org/Person"><a href="https://twitter.com/ayymanduh" class="social-embed-user" itemprop="url"><img class="social-embed-avatar social-embed-avatar-circle" src="data:image/webp;base64,UklGRv4CAABXRUJQVlA4IPICAADwCwCdASowADAAPrVKnUqnJCKhqqwA4BaJZgCzs3H+IuZyJDeXiL5owgKmpyy4gVaDU/JXr/RzDZp849wuL2gPPRMr/n4wAzCjjyfmadW445F6LSQ49gdgSmSL73B/LYyxHsalogUYgAD++9Ur9XMV/h/u0H3ITvFwyGKHv36ZFiG7CaxS+oFuGkMuJO0+PCytCgzYfrCkv5cQb143i0Ti9r8cfqovELVOQB8f3E/x/Is5LoYz43xhFKuUFztvAMWq7UAJ5U3jS1Dozq1q928722eoMwmq5T7eIk3ir9JyFGmLmxWgAPNWeXPQ16llDWb08HHRgFxUdfSUO+EO4Ha0DbprbUrPOTbU+fWKNWNKncBiaxBBYoV3sPI8ulEepBaDM7G1/vTZfvnVozNTqWHWrvWsdez+DJXId3hu6BGrjNV+DUaU1JYiKJBFwO6s2rdGONyAHmRDACW7lYURsQ8J4Y8qzAILHAUPOtCtAjGud55tl4ILS9BNyGRDKMDLSuBTGxtvjTNBsEkKK1Mq/Sllud44Jb/UTQsqf4rknVAW5GZ1FQj9MIZdWcebhl6PYqLKHL/Sz6/1WkIVqL5WgL08g9Ob4qz1RRV0IyYRBN+d0EmFgkUEAqFZHlwcvbXuCKJgxhAsy1R+Nvn5jRiLmNkJv6s3toewdznGQCpD2ymdCTFdInAKhGcpVS16jRvg4GRgDK7vqPpc4myH9djbCRrRQWKvAMmku5Qkj2vylYaETE161vUlu/xbj5/Vn0fmNAdmU4eN4cYg3fJf25ffEFuD2DVl18w8Ja5Iklm4VUUuMYa8m8GGzYLQLiG9fgTqNr0YEoizgHzU//DojexbUvyMz4Rq0LUByr3hFR/Ha69PKaOb6761fbLdouzT3+ti6ymrOtcgt3gqn7P/vmLCYs8Oy2v5fqJaBUy1M5v4py7/dpA6+PumLkJ1hFbgGlYyWbkJDfEIZvKpPkZ8d5+UO0LdjEOnf7Oe9zIJ6z1v07JCBWQA" alt="" itemprop="image"><div class="social-embed-user-names"><p class="social-embed-user-names-name" itemprop="name">Amanda 🏳️‍🌈🔮</p>@ayymanduh</div></a><img class="social-embed-logo" alt="Twitter" src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%0Aaria-label%3D%22Twitter%22%20role%3D%22img%22%0AviewBox%3D%220%200%20512%20512%22%3E%3Cpath%0Ad%3D%22m0%200H512V512H0%22%0Afill%3D%22%23fff%22%2F%3E%3Cpath%20fill%3D%22%231d9bf0%22%20d%3D%22m458%20140q-23%2010-45%2012%2025-15%2034-43-24%2014-50%2019a79%2079%200%2000-135%2072q-101-7-163-83a80%2080%200%200024%20106q-17%200-36-10s-3%2062%2064%2079q-19%205-36%201s15%2053%2074%2055q-50%2040-117%2033a224%20224%200%2000346-200q23-16%2040-41%22%2F%3E%3C%2Fsvg%3E"></header><section class="social-embed-text" itemprop="articleBody"><small class="social-embed-reply"><a href="https://twitter.com/edent/status/426271643980546048">Replying to @edent</a></small><a href="https://twitter.com/edent">@edent</a> I'm *slightly* biased here, but <a href="http://data.police.uk/docs/">data.police.uk/docs/</a>? : )</section><hr class="social-embed-hr"><footer class="social-embed-footer"><a href="https://twitter.com/ayymanduh/status/426278057846919169"><span aria-label="0 likes" class="social-embed-meta">❤️ 0</span><span aria-label="0 replies" class="social-embed-meta">💬 0</span><span aria-label="0 reposts" class="social-embed-meta">🔁 0</span><time datetime="2014-01-23T08:59:43.000Z" itemprop="datePublished">08:59 - Thu 23 January 2014</time></a></footer></blockquote>

<p>Not great for international audiences - but a fantastic resource for students in the UK.  All sorts of crime statistics.</p>

<h2 id="google-books"><a href="https://shkspr.mobi/blog/2014/04/wanted-simple-apis-without-authentication/#google-books">Google Books</a></h2>

<p>Google provides a free book search API which is simple to use.</p>

<pre>https://www.googleapis.com/books/v1/volumes?q=isbn:0747532699
</pre>

<p>And you get pretty-printed JSON back with information about the book.</p>

<h2 id="google-location"><a href="https://shkspr.mobi/blog/2014/04/wanted-simple-apis-without-authentication/#google-location">Google Location</a></h2>

<p>Google has a pretty good location API which doesn't require a login.</p>

<pre>https://maps.googleapis.com/maps/api/geocode/json?address=Oxford%20University,%20uk&amp;sensor=false
</pre>

<p>Again, with some pretty printed JSON.</p>

<h2 id="twitter-url-count"><a href="https://shkspr.mobi/blog/2014/04/wanted-simple-apis-without-authentication/#twitter-url-count">Twitter URL Count</a></h2>

<p>Twitter's APIs are usually heavily locked down - but there is one which is open.  It allows you to enter any URL and see how often it has been shared.</p>

<pre>http://urls.api.twitter.com/1/urls/count.json?url=http://www.bbc.co.uk/news/technology-26879185
</pre>

<p>The response is pretty simple.</p>

<pre>{"count":685,"url":"http://www.bbc.co.uk/news/technology-26879185/"}
</pre>

<h2 id="apple"><a href="https://shkspr.mobi/blog/2014/04/wanted-simple-apis-without-authentication/#apple">Apple</a></h2>

<p>Apple are surprisingly friendly.  They have a <a href="https://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html">simple API for looking up iTunes content</a>.</p>

<p>Here, for example is all of Beyoncé's music videos.</p>

<pre>https://itunes.apple.com/search?term=beyonce&amp;entity=musicVideo
</pre>

<h2 id="what-else"><a href="https://shkspr.mobi/blog/2014/04/wanted-simple-apis-without-authentication/#what-else">What Else?</a></h2>

<p>I'm sure I've missed loads.  If you know of any, please drop a link in the comments.</p>

<p>Remember, the criteria are...</p>

<ol>
<li>No authentication needed.</li>
<li>Well structured output.</li>
<li>Interesting data.</li>
<li>Child friendly.</li>
<li>Current.</li>
<li>Preferably free (libre and gratis).</li>
</ol>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=9614&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2014/04/wanted-simple-apis-without-authentication/feed/</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
			</item>
		<item>
		<title><![CDATA[New Python Pals - How To Help]]></title>
		<link>https://shkspr.mobi/blog/2013/06/new-python-pals-how-to-help/</link>
					<comments>https://shkspr.mobi/blog/2013/06/new-python-pals-how-to-help/#respond</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Sun, 23 Jun 2013 17:53:35 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[Python Pals]]></category>
		<guid isPermaLink="false">http://shkspr.mobi/blog/?p=8421</guid>

					<description><![CDATA[I&#039;ve spent the last few months sporadically writing stories to help young people code.  I&#039;ve now placed the four Python Pals stories up on GitHub.  Here&#039;s how you can help.       Write your own story and contribute it to the GitHub site (or send it directly to me).     Read the stories and let me know how they could be improved (spelling, grammar, plot).     Play test the adventures! Am I missing …]]></description>
										<content:encoded><![CDATA[<p>I've spent the last few months sporadically writing stories to help young people code.</p>

<p>I've now placed the <a href="https://github.com/edent/PythonPals">four Python Pals stories up on GitHub</a>.  Here's how you can help.</p>

<ol>
    <li>Write your own story and contribute it to the GitHub site (or send it directly to me).</li>
    <li>Read the stories and let me know how they could be improved (spelling, grammar, plot).</li>
    <li>Play test the adventures! Am I missing any vital steps? Can you or your children solve the mysteries?</li>
    <li>Illustrations! Do you have an artistic flair? Perhaps these stories would work better with some artwork?</li>
    <li>Spread the word!  Let people know that these stories exist.</li>
</ol>

<p>Please, take a look at <a href="https://github.com/edent/PythonPals">the Python Pals</a> and see if you're interested in helping.</p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=8421&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2013/06/new-python-pals-how-to-help/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title><![CDATA[The Python Pals Divine A Date]]></title>
		<link>https://shkspr.mobi/blog/2012/11/the-python-pals-divine-a-date/</link>
					<comments>https://shkspr.mobi/blog/2012/11/the-python-pals-divine-a-date/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Fri, 09 Nov 2012 07:45:22 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[NaBloPoMo]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Python Pals]]></category>
		<guid isPermaLink="false">http://shkspr.mobi/blog/?p=6664</guid>

					<description><![CDATA[The Python Pals Divine A Date  Penny was in a right grouch.  Her voice wobbled as she unloaded her woes on to her best friend, Poppy. &#34;It&#039;s all so unfair!&#34; She started to sob. &#34;Oh sweetie,&#34; said Poppy, &#34;I hate to say this, but you&#039;re sounding like a right stereotypical teenager!&#34; Penny cracked half a smile and blew her nose.  &#34;I know,&#34; she said &#34;But it&#039;s true. What can&#039;t I date him?&#34; Poppy…]]></description>
										<content:encoded><![CDATA[<h2 id="the-python-pals-divine-a-date"><a href="https://shkspr.mobi/blog/2012/11/the-python-pals-divine-a-date/#the-python-pals-divine-a-date">The Python Pals Divine A Date</a></h2>

<p>Penny was in a right grouch.  Her voice wobbled as she unloaded her woes on to her best friend, Poppy.
"It's all so <em>unfair</em>!" She started to sob.
"Oh sweetie," said Poppy, "I hate to say this, but you're sounding like a right stereotypical teenager!"
Penny cracked half a smile and blew her nose.  "I know," she said "But it's true. What <em>can't</em> I date him?"
Poppy sighed.  Penny's mum had banned her from seeing this boy - and it was causing no end of bother.
"Well, she explained, "they think he's too old for you. He is a bit grown-up."
Penny let out a little growl of rage "But I'm more mature than most grown-ups; half of them can't even <em>switch on</em> a computer - let alone program it as well as I can! "</p>

<p>This was true.  What Penny lacked in years, she more than made up for in talent.  No one at her school could even come close to her when it came to Python.  Even the teachers turned to her for help when they were stuck.</p>

<p>"You don't really want to go out with him, do you?" asked Poppy, "I mean, he's got all those zits."
It was Penny's turn to sigh, "No. No not really. And he does have a really annoying laugh. But I want the <em>right</em> to go out with him. That's what's unfair."</p>

<p>"Hang on..." Poppy was thinking.  What she lacked in coding skills, she made up for in tenacity and lateral thinking. "That <strong>may</strong> be unfair..."</p>

<p>Penny looked up from her disintegrating tissue. "I <em>know</em>," she pleaded.
"No, I mean literally unfair," Poppy paused, knowing she was getting in to dangerous territory, "What's the exact age difference between your parents?"</p>

<p>Penny's eyes began to twinkle - not with tears, but the hint of a mischievous idea...  "There's one way to find out," she grinned, "Let's get the Raspberry Pi!"</p>

<h3 id="the-difference-engine"><a href="https://shkspr.mobi/blog/2012/11/the-python-pals-divine-a-date/#the-difference-engine">The Difference Engine</a></h3>

<p>"Ok," said Penny, wiping her nose on her sleeve, "What comes first?"
They always worked best like this - Penny sat cross-legged in front of the computer plugging away on the code, while Poppy strode around the room pontificating on the problems.</p>

<p>"First," said Poppy "Does Python have a way to handle dates and times?"</p>

<p>"Oh yes," and Penny began typing.</p>

<pre lang="python">from datetime import date
</pre>

<p>"Basically, all you need to do is tell Python right at the start what special functions you want to be able to use. In this case, there are some built-in functions called 'datetime' and we just want those ones which deal with dates."</p>

<p>"Can we test it?" said Poppy cautiously. She always wanted to make sure that everything worked every step of the way.
"Sure!"</p>

<pre lang="python">print date.today()
</pre>

<p>"That should show us today's date," Penny ran the program and was rewarded with</p>

<pre>2014-03-24</pre>

<p>"Well," said Poppy "Why is it written in such a funny order?"
Penny loved explaining to her friend, she relished the look on her face when she finally understood something.
"So, the Americans write the date with the month first - like 12/11 means December the Twelfth. But to Europeans, it means Twelfth of November.  In order not to confuse anyone, most computers represent the data as 'YEAR-MONTH-DAY'."
"Oh, that makes a funny kind of sense.  So, that's today's date - how do we create a specific date?"
"It's pretty easy," Penny's hands danced over the keyboard, creating a pleasant clattering sound.</p>

<pre lang="python">my_birthday = date(2000, 02, 29)
</pre>

<p>"We create a variable and assign a date object to it. That's all."
"Alright, so what's zit-boy's birthday."
"As if I know!" said Penny in a scandalised tone of voice.
Poppy fixed her with her steely eyes and internally counted to ten.
Penny cracked by the time Poppy got to 7 and, in a small voice said "January 15th, 1998.
"Eugh! He was born <em>last century</em>!"
"Shut up."  She added the variable.</p>

<pre lang="python">his_birthday =
</pre>

<p><small>Add in the boy's birthday.</small></p>

<p>"So, your birthday, his birthday. How do we tell how much older he is?"
Penny thought for a second.
"Python is usually really good at doing maths on things.  What happens if we..." She trailed off, lost in code.</p>

<pre lang="python">difference = my_birthday - his_birthday
print "The difference is " + str(difference.days)
</pre>

<p>"The difference will be a date object - so we can ask it how many days it has. We also need to tell Python to cast it into a string, so that it will print out properly."
She ran the program.</p>

<p><small>Run the code on your computer now.</small></p>

<p>Poppy shrieked "He's <strong>ancient</strong>!"
It was Penny's turn to glare, "It just looks bad because it's written in days. Not in years and months."
Poppy leant back, and twiddled her hair between her thumbs.  "Right, so there are 365 days in a year..."
"Don't forget leap years," said Penny, who was touchy about the subject.
"Ok, 365 and a quarter."
"Well, that's easy enough to calculate. I'll take the number of days and divide it by 365.25."</p>

<pre lang="python">print difference.days / 365.25
</pre>

<p>Penny had to admit, that didn't make much of a difference. It <em>still</em> looked bad.</p>

<p>Poppy grinned, "Ok, so let's see what it says about your parents."</p>

<p>Penny rummaged around in her brain for a bit, "My mum was born on October 17th, 1975 - and dad was born December 24th 1972."</p>

<p>With a quick whisk round the keyboard she entered in the dates.</p>

<p>Penny gasped, "My parents are <em>such</em> hypocrites!" Both girls giggled.</p>

<p>Penny gave the Raspberry Pi a little pat on where she thought its head would be, "That's why we use computers - to make tricky things easy!"</p>

<p>She turned to her friend, "Let's do your parents next!"</p>

<p>The atmosphere in the room suddenly changed dramatically.  Poppy's memories of her father were still raw and painful.</p>

<p>"Pops," said Penny gently.
"No, it's ok," said her friend, with tears in her eyes. "But I think that's enough coding for today."</p>

<h3 id="a-midnight-nightmare"><a href="https://shkspr.mobi/blog/2012/11/the-python-pals-divine-a-date/#a-midnight-nightmare">A Midnight Nightmare</a></h3>

<p>It was close to midnight when Poppy snuck out of bed.  Quickly she flipped her phone on to quiet mode.  She strained her ears to see if her mother had heard the alarm.  Nothing.</p>

<p>Poppy silently slid out of bed. She slowly tip-toed over to her Raspberry Pi and switched it on.</p>

<p>She just <em>couldn't</em> let her mother hear her up at this hour!</p>

<p>Gently, she tapped her keyboard and subtly altered the Python code that Penny had written earlier.  She checked and double-checked her code.  There was <strong>no way</strong> she could afford to get this wrong.</p>

<p>Glancing around furtively, she inputted the today's date - 24th of March, 2014.</p>

<p>She shut her eyes tight, took a deep breath, and pushed down on the enter key.</p>

<p>For a full minute, she didn't dare open her eyes. She wanted to <em>so</em> badly, but knew that opening them would unleash more emotions than she knew how to deal with.</p>

<p>She screwed her courage to the sticking-place, and her eyes flicked open.  There, glowing gently on the screen were the words which made everything real - and made her die a little inside.</p>

<pre>Your father has been missing for: 101 days.</pre>

<h3 id="todo"><a href="https://shkspr.mobi/blog/2012/11/the-python-pals-divine-a-date/#todo">TODO...</a></h3>

<p>Can <strong>you</strong> work out when Poppy's father disappeared?</p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=6664&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2012/11/the-python-pals-divine-a-date/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title><![CDATA[Python Pals and the Letter Logjam]]></title>
		<link>https://shkspr.mobi/blog/2012/11/python-pals-write-a-worry/</link>
					<comments>https://shkspr.mobi/blog/2012/11/python-pals-write-a-worry/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Tue, 06 Nov 2012 07:50:56 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[NaBloPoMo]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Python Pals]]></category>
		<guid isPermaLink="false">http://shkspr.mobi/blog/?p=6631</guid>

					<description><![CDATA[This is the second of my &#34;Python Pals&#34; short stories.  They&#039;re designed to be solve-it-yourself puzzle stories to help kids learn the basics of programming.  All feedback welcome!  The Python Pals Write A Wrong  Poppy&#039;s mother, Ada, was not happy. &#34;I don&#039;t care about that,&#34; she shouted down the phone, &#34;Why am I always the one who has to pick up the pieces?&#34;  She carried on ranting.  Penny and…]]></description>
										<content:encoded><![CDATA[<p>This is the second of my <a href="https://shkspr.mobi/blog/2012/11/the-python-pals-program-a-problem/">"Python Pals" short stories</a>.</p>

<p>They're designed to be solve-it-yourself puzzle stories to help kids learn the basics of programming.</p>

<p>All feedback welcome!</p>

<h2 id="the-python-pals-write-a-wrong"><a href="https://shkspr.mobi/blog/2012/11/python-pals-write-a-worry/#the-python-pals-write-a-wrong">The Python Pals Write A Wrong</a></h2>

<p>Poppy's mother, Ada, was <strong>not</strong> happy.
"I don't care about that," she shouted down the phone, "Why am I always the one who has to pick up the pieces?"</p>

<p>She carried on ranting.  Penny and Poppy were sat in the lounge. Even though the TV volume was quite high, they could still hear snatches of the conversation.
Suddenly, the door burst open and Ada stormed in, "What are you two doing right now?" she demanded.</p>

<p>"Just watching TV," said Poppy, "It's the episode where they..." but before she got a chance to finish, her mother interrupted.
"Nothing then. Good. You can make yourselves useful."
"But <em>mum</em>!"
"But nothing.  I need to go into town to deal with.... just into town. I'm not going to have a chance to type up all these thank you letters. So I need you to do it."
Penny smiled sweetly at her friend's mother, "Sure thing, Ada, we'd be happy to!"
"Good. It's settled. And please get them all done by the time I get back. I need to get them sent and I..." she looked close to tears.
"Don't worry, mum, we'll get them done."
Ada gave a weak smile, kissed her daughter on the forehead, and left without saying a word.</p>

<p>Penny turned to her pal and said, "Let's get cracking!"</p>

<p>They ran into Ada's work room.  It was plainly furnished, although the desk was a mess of papers.  A vase sat in the corner, its flowers long since withered.</p>

<p>"What's all this about, Poppy?" asked Penny.</p>

<p>"There's loads of really yucky diseases out there and mum's been raising money to make sure that young women stay healthy. Now, where does my mum keep her pen and paper?"</p>

<p>Penny fixed Poppy with a steely glare - the one she usually reserved for people who asked if she wanted to take up cross-country running, or some other mad sport.</p>

<p>"What do you want to write them all by hand for?" She asked.  Out of her blue and white school rucksack she pulled her Raspberry Pi and set it up on the desk.</p>

<p>Poppy passed Penny a USB stick which had been nestling in a collection of newspaper clippings on her mother's desk, "All of the donors should be on there."</p>

<p>Penny plugged the stick into the Raspberry Pi.  She fiddled around until she could see its file system.</p>

<p>"Aha, there we go!" Penny said triumphantly "Let me just open it up."</p>

<p>A few clicks later and the text file displayed on the screen.  It showed the names of all the donors and how much they'd given.</p>

<pre>Anna 2.50
Beth 5.93
Cath 23.50
Dom 15
Erik 3.14
...
</pre>

<p>(<a href="https://shkspr.mobi/blog/wp-content/uploads/2012/11/donors.txt">You can download the file to your computer</a>)</p>

<p>The file kept on scrolling and scrolling.</p>

<p>Poppy shrieked, "There's well over a hundred names here! We're never going to be able to finish all these letters by the time my mum comes back! Not even you are that fast a typist."</p>

<p>"Pops," said Penny, "I don't want to be mean - but you're being <em>incredibly</em> thick. So utterly, mind bendingly dense that I'm not sure if we can be friends any more." Very loudly and slowly she said "We have a computer, you prat! We'll get the Pi to do the hard work for us!"</p>

<p>Poppy looked sheepish, "Oh... Yeah. Wait! I suppose we can use Python to get this done in a few minutes?"</p>

<p>Penny put on her cheesiest American accent and drawled, "Got it in one, partner."</p>

<p>When they had both regained their composure, Penny perched on a chair with both legs tucked underneath her. Poppy hopped up on the windowsill so she could see the screen and her friend at the same time.</p>

<p>Poppy started, "Well, let's break it down in to easy to manage chunks.  You've got a file with the names and amounts people have given, right?"
"Right."
"Ok, so we want to read in each line of the file, then create a letter based on the information."
"That should be pretty easy, Pops." Penny stretched out her fingers and started typing. She was most at home when her fingers were flying over the keyboard.  As she typed, she spoke.</p>

<p>"It just takes one line of code to open a file. You just tell Python where the file is, and if you want to read to the file or write to the file."</p>

<pre lang="python">textfile = open('donors.txt', 'r')
</pre>

<p>"Our file is in the same directory as this Python program, and we only want to read it.  To see if we've got the right file, we can tell Python to display its contents."</p>

<pre lang="python">print textfile.readlines()
</pre>

<p>She saved the program and ran it.  The file displayed itself in the console.</p>

<p>"Great," said Poppy, grinning, "One task down. Now every line just has the person's name and how much they donated, right?"
"Yup. So we can read the file a line at a time and do something with each line.  Watch."</p>

<p>She deleted her code and started again</p>

<pre lang="python">textfile = open('donors.txt', 'r')
lines = textfile.readlines()

for line in lines:
   chunks = line.split()
   donor_name = chunks[0]
   donor_amount = chunks[1]
   print donor_name
</pre>

<p>"So," she said methodically, "We open the file. We get every line. We split every line based on spaces. Of those two chunks, we called the first the donor's name, and the second the donor amount. Then we print out the donor's name - just to be sure."</p>

<p>Her finger hovered over the keyboard. Just as she was about to run the program, Poppy interrupted.</p>

<p>"Hang on. Why is 'donor_name' coming from chunk zero? Shouldn't it be from one - and the amount from chunk two?"</p>

<p>"Ah," said Penny, "In Python - and most other languages - lists always start from zero."
"That's dumb," said Poppy.
"You get used to it."
"But what's the point in that?"
"Well, think of the years. We're in the 2000s now.  The first year of the 2000 was - obviously - 2000. The second year was 2001, the third was 2002 and so on."
"Oh!" said Poppy, as things clicked into place, "That makes sense... kinda..."
"As I said, you get used to it. Now, where were we?"
"Right, we want to say something like 'Dear donor_name, Thanks for your donation, blah blah blah, etc'"
"You are <em>so eloquent</em>!" Penny's sarcasm flew out before she could stop herself.  She carried on typing, adding the following lines.</p>

<pre lang="python">   letter = "Dear " + donor_name + ", "
   letter += "Thank you for your donation of " + donor_amount
   print letter</pre>

<p>"When you add two strings of text together," she explained, "Python just sticks them next to each other - it's called concatenation."
"But what are those plus-equals symbols for?"
"If you want to add something on to an existing variable, you could say</p>

<pre>whatever = whatever + something</pre>

<p>but it's quicker to say</p>

<pre>whatever += something</pre>

<p>"
"Ooooh!" gasped Poppy - who was very good at interjecting with what she perceived as helpful comments, "Make it say 'Generous Donation'!"
"Yeah, but some of the people <em>weren't</em> very generous."
"Well, that's easy enough to solve. Only say generous if they gave more than £10."
"Of course!" Said Penny, "Why didn't I think of that?"
"Hey! That's why we're such good friends - I'm the brains and you're the...." Poppy trailed off.
"The typist?" Penny said scornfully as she, hammered the keys angrily.</p>

<pre lang="python">   letter += "Thank you for your "
   if float(donor_amount) &gt; 10:
</pre>

<p>"What does 'float' mean?" asked Poppy.
Penny turned in her chair to face her friend, "Ok, our Python code has read a string of text from the file, right?"
"Yup"
"So it thinks that '5' is the character '5' not the <em>number</em> '5'."
"Ah! So if you had '5'+'2' it would be '52'."
"Bazinga! So, we need to 'cast' the character into the number. Think of it like casting a spell on someone to look like a frog."
The light dawned on Poppy's face. "I see! So when you say 'float(donor_amount)' you're saying to Python 'Imagine that this is a number'"
Penny nodded and carried on typing.</p>

<pre lang="python">   letter += "Thank you for your "
   if float(donor_amount) &gt; 10:
      letter += "very generous "
   letter += "donation of " + donor_amount
   print letter
</pre>

<p>"It's just simple maths. You can use &gt; for seeing if something is greater than something else, or &lt; for less than."
Poppy peered at the keyboard.  She cleaned her glasses and peered again. "So where's the greater-than-or-equal-to key?"
"There isn't one.  You just have to type the equals key afterwards like &gt;= or &lt;="
"Nifty. Oh, and not to criticise, but you left off the £ symbol on the donor amount."</p>

<p>Penny deftly changed the line to read:</p>

<pre lang="python">   letter += "donation of £" + donor_amount
</pre>

<p>But this time, when she ran the program, something unexpected happened.</p>

<p><small>Now run the code on your computer</small></p>

<pre>SyntaxError: Non-ASCII character 'xc2' in file letter.py on line 9, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details</pre>

<p>Both girls swore in unison.  There always seemed to be something to trip them up.
"Computers," opined Penny, "Can be really dumb sometimes. They hate it when you use funny symbols."
Poppy considered this, "So we need to tell it what characters we'll be using?"
"Pretty much. We just need to pop this line at the top of our code." Penny scrolled to the top and tapped out the magic incantation.</p>

<pre lang="python"># This Python file uses the following encoding: utf-8
</pre>

<p>"That ought to do it."
"So, we've got their name, a message, and how much they donated. What else is there?
"Nothing!" sang Penny, "Let's carry on watching TV."
"How about," continued Poppy, blithely ignoring her friend, "How about we told them what their donation has bought?"
"Or, we could <em>carry on watching TV</em>!"
"No, if a job's worth doing, it's worth doing properly."
"<em>Fine</em>!" Penny huffed, "How much did each vaccination cost?"
Poppy scrabbled around on her mother's desk, studiously ignoring all the legal papers on there, until she found the document she was looking for.
"£1.34 per vaccine."</p>

<p>"That's pretty easy," said Penny, "We'll create a variable for the vaccine cost, then divide the amount donated by that.</p>

<pre lang="python">vaccine_cost = 1.34
vaccines_bought = float(donor_amount) / vaccine_cost
letter += ".  That enabled us to buy " + str(vaccines_bought) + " vaccines."
</pre>

<p>"Obviously, we'll have to cast the number back to a string so we can stick it in to the letter." said Penny.</p>

<p>Poppy got a smug grin on her face, "You're going to have a problem there, Pen."
"What on Earth are you talking about?"
"Run it and see..."</p>

<p><small>Now run the code on your computer</small></p>

<p>Penny ran the program. She stared at the output, twitched her nose and shouted "Rattlesnakes!"
"The problem," Poppy sighed, "is that computers are <em>really</em> precise. Much more so than humans."
"Stupid humans," muttered Penny.
"So, can we just round things down using the 'round()' function?" said Poppy, conspicuously ignoring her friend's desire to transcend humanity and become one with the machines.
Penny typed away.</p>

<pre lang="python">round( float(donor_amount) / vaccine_cost )
</pre>

<p>"That's pretty much it, isn't it?" asked Penny plaintively.
"Yup, let's run off these letters and get back to the TV. If we're lucky, we won't have missed too much."</p>

<p>A short while later, Ada swung into the house, her humour looking much improved.
"Girls? Where are you?"
"In here, mum," called Poppy.
"What on Earth are you doing in the TV room?" Said Ada, suddenly looking furious, "I thought I asked you to..."
"Chill, mum," her daughter interrupted. "It's all done."
"What?" Said Ada, clearly baffled, "How could you have done all of those letters? There were at least a hundred."
"One hundred and twenty-eight," chimed in Penny.</p>

<p>They handed over a sheaf of paper to a dumbstruck Ada.</p>

<p>"But this is marvellous!" she cried, "What wonderful letters - and how clever of you to add in the details about how many vaccines their donations were worth!"</p>

<p>"Oh, it was nothing," said Poppy airily. "Now," she continued, "We're quite exhausted after all our hard work. Perhaps you would be so kind as to bring us some ice cream?"</p>

<p>"After all this," beamed Ada, "Ice cream floats for the pair of you!"</p>

<p>"With chocolate sprinkles?"</p>

<p>"Don't push your luck, young lady!" And with that, she twirled off into the kitchen.</p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=6631&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2012/11/python-pals-write-a-worry/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title><![CDATA[The Python Pals Program A Problem]]></title>
		<link>https://shkspr.mobi/blog/2012/11/the-python-pals-program-a-problem/</link>
					<comments>https://shkspr.mobi/blog/2012/11/the-python-pals-program-a-problem/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Sat, 03 Nov 2012 07:00:45 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[NaBloPoMo]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Python Pals]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<guid isPermaLink="false">http://shkspr.mobi/blog/?p=6560</guid>

					<description><![CDATA[As mentioned earlier, I&#039;ve been inspired by the Byte Brothers to create a mystery story which kids have to solve using their l33t h4x0r skillz in Python.  This is loosely based on The Byte Brothers Go to a Getaway, by Lois and Floyd McCoy.  My well-thumbed copy  was printed in 1984. I&#039;m not sure when I got it, but I remember being around 8 or 9 when I first started writing programs in BASIC. …]]></description>
										<content:encoded><![CDATA[<p>As mentioned earlier, I've been inspired by the Byte Brothers to create a mystery story which kids have to solve using their l33t h4x0r skillz in Python.</p>

<p>This is loosely based on The Byte Brothers Go to a Getaway, by Lois and Floyd McCoy.
<img src="https://shkspr.mobi/blog/wp-content/uploads/2012/11/Byte-Brothers-Go-To-A-Getaway.jpg" alt="Byte Brothers Go To A Getaway" title="Byte Brothers Go To A Getaway" width="240" height="307" class="alignleft size-full wp-image-6581">
My well-thumbed copy  was printed in 1984. I'm not sure when I got it, but I remember being around 8 or 9 when I first started writing programs in BASIC.  Sadly, BASIC is as outdated as the Lascaux Cave Paintings, so I've written this in more friendly Python.</p>

<p>My hope is that people will write a bunch of interesting mystery stories (using these characters or their own) release them as Creative Commons, then we can put out a book AND SAVE THE WORLD!</p>

<p>Ahem...</p>

<p>Without further ado, I present to you the first adventure of "The Python Pals"!
<a rel="license" href="http://creativecommons.org/licenses/by/2.0/uk/deed.en_GB"><img alt="Creative Commons Licence" style="border-width:0" src="https://licensebuttons.net/l/by/2.0/uk/88x31.png"></a><br>This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/2.0/uk/deed.en_GB">Creative Commons Attribution 2.0 UK: England &amp; Wales License</a>.</p>

<h2 id="the-morse-code-mystery"><a href="https://shkspr.mobi/blog/2012/11/the-python-pals-program-a-problem/#the-morse-code-mystery">The Morse Code Mystery</a></h2>

<h3 id="the-beachcombers"><a href="https://shkspr.mobi/blog/2012/11/the-python-pals-program-a-problem/#the-beachcombers">The Beachcombers</a></h3>

<p>The waves crashed angrily on the beach, and the rain seemed to come in from all directions.  A sudden gust blew a thin drizzle straight down Poppy's collar.
"This weather is <em>foul</em>," she spat.
"Just five more minutes," yelled Penny.</p>

<p>Poppy collapsed herself until she was eye level with her friend Penny.  Even though Penny was the shorter of the two, she was hunched down on the beach anxiously glancing at the shoreline.</p>

<p>"Penny, what are we doing here? It's cold, wet, and most importantly," she paused for dramatic effect, "We're going to miss the Food Network's 'Marzipan Marathon'!"
Her friend giggled - neither of them could stand those TV cookery channels - but they had agreed there was something oddly compelling about watching a man trying to eat his body weight in cake.
"There!" Yelled Penny, pointing a little way down the shoreline. "I told you that interesting stuff gets washed up here when there's a storm. Grab it!"</p>

<p>Penny was used to being bossed around by Poppy.  Despite being the older of the two friends, she was always being treated like Poppy's younger sister - so she relished in the chance to bark orders at her.</p>

<p>Penny scooped up the large square of blue canvas a spun around.  "Please can we go in now?" she whined, "It's cold and wet and..."</p>

<p>Before she could even finish her sentence, Poppy exclaimed "Look! Look at the cloth!"</p>

<p>They both stared at the raggedy square of canvas.  It was peppered with strange white marks.</p>

<p>"Let's get home and work out what this is," said Poppy. With that, she snatched the cloth from Penny, and started sprinting away toward her parent's home.</p>

<p>"That just what <em>I was about to say</em>!" yelled Penny, as she slowly trudged up the beach.</p>

<h3 id="pi-power"><a href="https://shkspr.mobi/blog/2012/11/the-python-pals-program-a-problem/#pi-power">Pi Power</a></h3>

<p>"Will you be wanting some soup, girls?" asked Poppy's mum, Ada.  She had gotten used to both of them storming in and expecting to be fed.
"No time Ada, thanks," said Penny breathlessly, "We've got to work out what this is."</p>

<p>"Hmmm, looks like old fashioned Morse Code to me," said Ada after a moment's cursory examination of the cloth.  "Where on Earth did you find..."</p>

<p>"Can we get some soup and croutons, and maybe some cheese. Do we have any crisps?" yelled Poppy as the girls bolted upstairs.</p>

<p>They flipped on the Raspberry Pi.  It had been a birthday present from Poppy's dad.  One of the few things she had left to remember him by.  Just as Linux was quickly booting up, there was an enormous crack of thunder which shook the whole house. The lights flickered, then went off.</p>

<p>A second later they were back on, but there was a strange burning smell.</p>

<p>"Oh no! Cried Penny, "The router!"</p>

<p>Where their Internet router had been was a smouldering lump of twisted plastic and metal.</p>

<p>Poppy said a word which, if her mother had overheard her would have meant an instant reduction in pocket money.  "How will we find out what 'Morse Code' is if we can't get online?"</p>

<p>The girls sat, stunned.  No Internet.  No Facebook. More importantly, no Wikipedia!</p>

<p>They looked at their phones but, as always they didn't have any credit.</p>

<p>Poppy looked around the room forlornly.  The little study had been Poppy's dad's work area before he... Well. Just before.  As she scanned the shelves looking for something which might help - even an old fashioned dial-up modem would do.</p>

<p>Penny suddenly chirruped, "Pops, what's the 'Encyclopedia Britannica'?" Pointing to an imposing set of books on a shelf.
"No idea," sniffed Poppy despondently.
"Only, and I know it was your dad's, but 'encyclopedia' sounds a bit like 'Wikipedia' and I wondered..."
<a title="By Encyclopedia Britannica (scanned by Infrogmation, pulished on en WP) [Public domain], via Wikimedia Commons" href="http://commons.wikimedia.org/wiki/File%3AAd_Encyclopaedia-Britannica_05-1913.jpg"><img width="256" alt="Ad Encyclopaedia-Britannica 05-1913" src="//upload.wikimedia.org/wikipedia/commons/d/d8/Ad_Encyclopaedia-Britannica_05-1913.jpg"></a>
"Of course! Quick, which one of the books has 'M' printed on the side?" Poppy smiled. It was rare to see her smile these days, and Penny relished cheering her friend up.</p>

<p>They plucked the dusty volume from the shelf and opened it up more-or-less at random.  Its musty smell filled the room and they began flicking through the yellowing pages.
"Where's the search function on this thing?" joked Penny.
"Möbius, Moomins, Mormon, Morse!"</p>

<p>There, laid out in the pages of the encyclopedia was a guide to Morse Code.</p>

<p><a title="By Rhey T. Snodgrass and Victor F. Camp [Public domain], via Wikimedia Commons" href="https://upload.wikimedia.org/wikipedia/commons/e/e9/International_Morse_code.png"><img width="256" alt="Intcode" src="https://upload.wikimedia.org/wikipedia/commons/e/e9/International_Morse_code.png"></a></p>

<p>The girls flipped on the Pi and waited for it to boot.</p>

<p>"The most important thing to consider when programming," said Poppy doing her very best imitation of Mr Cartwright their inexcusably dull IT teacher.
"...is planning!" said Penny, finishing her friend's sentence.</p>

<p>"We want a program which will let us type in each letter of Morse Code and then show us the English translation."</p>

<p>Penny grabbed the keyboard. She knew that she would be doing most of the typing while Poppy did most of the pointing out of her mistakes.  Apparently, this was known as "pair programming" according to Mr Cartwright. She didn't think much of it.</p>

<p>"First," said Poppy, "Let's define a <a href="http://docs.python.org/2/tutorial/datastructures.html#dictionaries">dictionary</a> of English and Morse Code."</p>

<p>Penny's hands darted across the keyboard as her friend read the dots and dashes from the book.</p>

<pre lang="python">morse = {  '.-'  :'A', '-...':'B', '-.-.':'C', '-..' :'D', '.'   :'E',
           '..-.':'F', '--.' :'G', '....':'H', '..'  :'I', '.---':'J'
        }
</pre>

<p><small>You can program the rest of the dictionary yourself.</small></p>

<p>Poppy sighed, "Why on Earth have you bothered to line up all the letters?"
"It helps me think," said Penny defensively, "I like it neat. Besides, Python doesn't care how I space things like that."
"Fine! Let's do a quick test to see if it works," said Poppy.
"Right, I'll ask the user to type a single letter of Morse Code. Then it's really easy to look it up in the dictionary," said Penny.</p>

<pre lang="python">get_code = raw_input('Type a Morse Character ')
print morse[get_code]
</pre>

<p>She ran the program.  As expected it asked her to type in a code.  She hit the sequence ".-" and hit enter.</p>

<p>She was rewarded with a glowing "A" on the screen.</p>

<p>"Good start," said Poppy. "But it's going to be a pain to type in every Morse character, then hit enter, then try to string the letters together."</p>

<p>Penny thought for a moment. She knew she could come up with something clever.</p>

<p>"How about we read in the string we type in, then break it up based on where the spaces are?" She said tentatively.
Poppy looked confused, "What do you mean, Pen?"</p>

<p>Penny ran Python directly so she could show what she was thinking</p>

<pre>Python 2.7.3 (default, Aug  1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; </pre>

<p>At the prompt she typed</p>

<pre lang="python">&gt;&gt;&gt; "This is a test".split()
</pre>

<p>"If I'm right, the <a href="http://docs.python.org/2/library/string.html#string.split">.split()</a> function will give us an list of all the word."</p>

<p>She gently thumbed the enter key.</p>

<pre>['This', 'is', 'a', 'test']</pre>

<p>"Yes!" Shouted both girls simultaneously.</p>

<p>"So now we will have each Morse Letter in a list, then we want to look it up in the dictionary."
"That's right. Luckily it's super simple to do something on every item in a list - look,"</p>

<p>Penny typed directly into Python again.</p>

<pre lang="python">&gt;&gt;&gt; list_of_words = "This is a test".split()
&gt;&gt;&gt; for item in list_of_words:
... print item
</pre>

<p>But this time, when she hit enter, an error message popped up!</p>

<pre>  File "<stdin>", line 2
    print item
        ^
IndentationError: expected an indented block
</stdin></pre>

<p>This time it was Penny's turn to swear.</p>

<p>"Wipe that grin off your face! Yes, <a href="https://web.archive.org/web/20120510172415/https://www.secnetix.de/olli/Python/block_indentation.hawk">spacing and indentation are important in Python</a>. But generally it's fine if I line up my code just how I like it."</p>

<p>She tried again. This time hitting the spacebar as hard as she thought it could stand.</p>

<pre lang="python">&gt;&gt;&gt; list_of_words = "This is a test".split()
&gt;&gt;&gt; for item in list_of_words:
...    print item
</pre>

<p>This time, the result was a lot more satisfactory.</p>

<pre>...
This
is
a
test
&gt;&gt;&gt;
</pre>

<p>"Getting there," muttered Poppy under her breath.  They swiftly changed the last few lines of their code to read:</p>

<pre lang="python">get_code = raw_input('Type in the Morse Code ')

code_list = get_code.split()

for item in code_list:
   print morse[item]
</pre>

<p>"Ok," said Penny, "Let's see what this mysterious blue cloth says on it..."</p>

<pre>...  ---  ...  -...  ---  .- -  ...  .-  -.  -.-  ---  -.  ..  ...  .-..  .-  -.  -..</pre>

<p>They checked and double checked what they had typed in.</p>

<p>"Ready?" said Poppy.
"Let's do it!" said Penny as she hit the enter key.</p>

<h3 id="saving-the-day"><a href="https://shkspr.mobi/blog/2012/11/the-python-pals-program-a-problem/#saving-the-day">Saving The Day</a></h3>

<p>"Well done you two," said the Mayor. "Without your help, that sailor would have been stuck there a long time."</p>

<p>Penny and Poppy both grinned. It had all been such a rush, they'd gone from running their code, to screaming for Poppy's mum, to calling the coastguard, to seeing a shipwrecked sailor being rescued.  They had been interviewed for TV and the clip had <em>hundreds</em> of YouTube likes.</p>

<p>There was even a Facebook page dedicated to thanking them!</p>

<p>The Mayor had decided that such fine upstanding citizens deserved a reward - and had invited them to a special event in the town hall.</p>

<p>"Who would have thought two girls would know Morse Code?" They Mayor said, "Did you learn that at school?"</p>

<p>Penny fixed him with a steely glare, "No. We taught ourselves."</p>

<p>The Mayor peered over his glasses, "But surely you had help from someone? An older brother perhaps?"</p>

<p>Poppy knew the look on Penny's face and answered before her friend lost her temper, "I think you'll find," she said sweetly, "that <strong>women</strong> don't need help from <strong>boys</strong>!"</p>

<p>Poppy felt Penny's hand slip in to hers. She started to chuckle as her hand was squeezed in firm but measured bursts.</p>

<pre>-  ....  .-  -  ...  .--  ....  -.--  -.--  ---  ..-  .-  .-.  .  --  -.--  -...  .  ...  -  ..-.  .-.  ..  .  -.  -..</pre>

<p>THE END</p>

<h2 id="what-next"><a href="https://shkspr.mobi/blog/2012/11/the-python-pals-program-a-problem/#what-next">What Next</a></h2>

<ul>
    <li>Write your own story - using these character or ones you've created.</li>
    <li>Make the Python simple and readable - explain as you go.</li>
    <li>If there's enough interest, I'll gather them all up, maybe on a central site.</li>
    <li>Perhaps, if people like them, we can release a (free) ebook?</li>
    <li>Oh, and feel free to criticise my storytelling abilities or coding deficiencies!</li>
</ul>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=6560&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2012/11/the-python-pals-program-a-problem/feed/</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
			</item>
		<item>
		<title><![CDATA[Time To Resurrect The Byte Brothers?]]></title>
		<link>https://shkspr.mobi/blog/2012/11/time-to-resurrect-the-byte-brothers/</link>
					<comments>https://shkspr.mobi/blog/2012/11/time-to-resurrect-the-byte-brothers/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Fri, 02 Nov 2012 11:30:46 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[byte brothers]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[NaBloPoMo]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Python Pals]]></category>
		<category><![CDATA[scratch]]></category>
		<guid isPermaLink="false">http://shkspr.mobi/blog/?p=6446</guid>

					<description><![CDATA[I&#039;m currently getting involved in the Coding For Kids scene. I&#039;m setting up a workshop in my local library to teach kids programming - specifically, the MIT language Scratch.  I&#039;ve been left slightly dissatisfied with the unstructured nature of the Scratch teaching materials. While it&#039;s quite fun to teach a cat to dance - it doesn&#039;t seem to be building up to anything.  I&#039;m also working with…]]></description>
										<content:encoded><![CDATA[<p>I'm currently getting involved in the <a href="http://www.codeclub.org.uk/">Coding For Kids scene</a>. I'm setting up a workshop in my local library to teach kids programming - specifically, the MIT language <a href="http://scratch.mit.edu/">Scratch</a>.</p>

<p>I've been left slightly dissatisfied with the unstructured nature of the Scratch teaching materials. While it's quite fun to teach a cat to dance - it doesn't seem to be building up to anything.</p>

<p>I'm also working with <a href="http://appsforgood.org/">AppsForGood</a> - it's a project run in secondary schools which aims to get students to research, design, and build a mobile application which will be useful to them or their community.</p>

<p>One of the things I love about it is the students are often trying to solve their own real-world issues. There's a definite sense that they have identified a problem and are working towards a goal.</p>

<p>That's when I remembered The Byte Brothers! In the mid-eighties I somehow chanced upon the mysterious sounding <a href="http://openlibrary.org/works/OL15553835W/The_Bytes_Brothers_go_to_a_getaway">The Byte Brothers Go To A Getaway by Lois &amp; Floyd McCoy.</a></p>

<p><a href="http://www.computinghistory.org.uk/det/12994/The-Bytes-Brothers-Program-a-Problem-2/"><img class="alignleft  wp-image-6447" title="Byte Brothers Cover" src="https://shkspr.mobi/blog/wp-content/uploads/2012/10/Byte-Brothers-Cover.jpg" alt="Byte Brothers Cover" width="237" height="384"></a></p>

<p>"The Byte Brothers" were a series of "solve it yourself" adventures. You read the story, and had to attempt to solve the mystery using BASIC. A typical puzzle involved working out average speed, learning how to use loops to generate "I must not cheat in class" lines for detention, and decoding Morse code.</p>

<p>They stepped through the code as they went - explaining how it all worked and what you could do to change the program. You coded as you went along, until you completed the task.</p>

<p>I <em>loved</em> them. I was a sucker for adventure books, and I adored the thrill of being able to solve a crime using my trusty BBC Micro.</p>

<p>The books, sadly, seem <a href="http://www.goodreads.com/author/show/349264.Lois_McCoy">out of print</a>. There is virtually no information on the web about the Byte Brothers, nor Lois McCoy. Even Wikipedia is silent on the subject.</p>

<p>I think it's time to resurrect the spirit of the Byte Brothers! Is it possible to create a series of mystery short stories which can solved using, say, Python?</p>

<p>I think so!  I'll try to write a few solve-it-yourself adventure stories and publish them on here.  If you want to write a story - go ahead. If we get enough momentum behind this, I think it could really engage kids (and adults) into learning to code.</p>

<p>So, stay tuned for tomorrow's exciting story "The Python Pals Program A Problem"!</p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=6446&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2012/11/time-to-resurrect-the-byte-brothers/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
	</channel>
</rss>
