{"id":414,"date":"2017-08-07T12:40:20","date_gmt":"2017-08-07T12:40:20","guid":{"rendered":"https:\/\/www.triptera.com.au\/wordpress\/?p=414"},"modified":"2017-08-07T12:40:20","modified_gmt":"2017-08-07T12:40:20","slug":"getting-started-with-python","status":"publish","type":"post","link":"https:\/\/www.triptera.com.au\/wordpress\/2017\/08\/07\/getting-started-with-python\/","title":{"rendered":"Getting started with Python"},"content":{"rendered":"<p>There are many online resources for beginning in python. Here are a few<\/p>\n<p><a href=\"https:\/\/wiki.python.org\/moin\/BeginnersGuide\/NonProgrammers\">https:\/\/wiki.python.org\/moin\/BeginnersGuide\/NonProgrammers<\/a> &#8211; Python&#8217;s own suggestions for getting started<br \/>\n<a href=\"http:\/\/www.letslearnpython.com\/learn\/\">http:\/\/www.letslearnpython.com\/learn\/<\/a> &#8211; An online tutorial for kids used at PyCon each year<br \/>\n<a href=\"http:\/\/kata.coderdojo.com\/wiki\/Python_Path\">http:\/\/kata.coderdojo.com\/wiki\/Python_Path<\/a> &#8211; Some international CoderDojo resources<\/p>\n<p>At Kenmore CoderDojo Term 3 2017 we are going to be using Python 3. We will also be using Python with Minecraft. For full setup instructions, refer to <a href=\"https:\/\/www.triptera.com.au\/wordpress\/2017\/06\/02\/coderdojo-minecraft-with-python-setup\/\">https:\/\/www.triptera.com.au\/wordpress\/2017\/06\/02\/coderdojo-minecraft-with-python-setup\/<\/a><\/p>\n<h3>Python shell<\/h3>\n<p>At our first session, we installed Python 3.6.2 and used the IDLE development environment for running python in a shell.<\/p>\n<p>Python can use operators +, -, *, \/, \/\/, % and ** to preform mathematical operations<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n&gt;&gt;&gt; 5 + 3\r\n8\r\n&gt;&gt;&gt; 5 - 3\r\n2\r\n&gt;&gt;&gt; 5 * 3\r\n15\r\n&gt;&gt;&gt; 5 \/ 3\r\n1.666666666667\r\n&gt;&gt;&gt; 5 \/\/ 3\r\n1\r\n&gt;&gt;&gt; 5 % 3\r\n2\r\n&gt;&gt;&gt; 5 ** 3\r\n125\r\n<\/pre>\n<p><code>+ addition<br \/>\n- subtraction<br \/>\n* multiplication<br \/>\n\/ division (decimal)<br \/>\n\/\/ division (integer)<br \/>\n% modulo (remainder from division)<br \/>\n** to the power of<\/code><\/p>\n<h3>Variables<\/h3>\n<p>To store data in memory, create a name for the memory location, and assign it using the <code>=<\/code> sign. These memory locations are called variables because you can change the data in them. Type the variable name by itself to see the value stored in it. You can use variables in mathematical equations.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n&gt;&gt;&gt;speed=50\r\n&gt;&gt;&gt;duration=3\r\n&gt;&gt;&gt;speed\r\n50\r\n&gt;&gt;&gt;speed * duration\r\n150\r\n<\/pre>\n<h3>Python program<\/h3>\n<p>When using the shell the commands are not saved. By putting the commands in a file they can be run over and over again without having to be retyped. In IDLE choose <code>New File<\/code> from the <code>File<\/code> menu and type the following<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nprint(3)\r\nprint(2)\r\nprint(1)\r\nprint(&quot;blast off&quot;)\r\n<\/pre>\n<p>Save this file from the <code>File<\/code> menu. From the <code>Run<\/code> menu select <code>Run module F5<\/code>. Every time you run it you will see the same output in the shell window.<\/p>\n<p><code>3<br \/>\n2<br \/>\n1<br \/>\nblast off<\/code><\/p>\n<h3>Using loops to save typing<\/h3>\n<p>Loops are sections of code which are run multiple times. <code>while<\/code> loops will keep looping until a specified condition is <code>True<\/code>. The indented lines indicate which part of the code is included in the loop. <\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nx = 5\r\nwhile x &gt; 0:\r\n    print(x)\r\n    x -= 1\r\nprint(&quot;blast off&quot;)\r\n<\/pre>\n<p>The condition is <code>x > 0<\/code> which is <code>True<\/code> for 10 loops and then becomes <code>False<\/code> when the value of <code>x<\/code> is zero.<br \/>\nThe command <code>x -= 1<\/code> is a shorthand for telling python to reduce the value of <code>x<\/code> by 1 every time it is run.<br \/>\nThis program gives the following output every time it is run.<\/p>\n<p><code>5<br \/>\n4<br \/>\n3<br \/>\n2<br \/>\n1<br \/>\nblast off<\/code><\/p>\n<p>Only one line needs to be changed to start the countdown from a different number.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are many online resources for beginning in python. Here are a few https:\/\/wiki.python.org\/moin\/BeginnersGuide\/NonProgrammers &#8211; Python&#8217;s own suggestions for getting started http:\/\/www.letslearnpython.com\/learn\/ &#8211; An online tutorial for kids used at PyCon each year http:\/\/kata.coderdojo.com\/wiki\/Python_Path &#8211; Some international CoderDojo resources At Kenmore CoderDojo Term 3 2017 we are going to be using Python 3. We will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"categories":[13],"tags":[],"class_list":["post-414","post","type-post","status-publish","format-standard","hentry","category-coderdojo"],"_links":{"self":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/414","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/comments?post=414"}],"version-history":[{"count":2,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/414\/revisions"}],"predecessor-version":[{"id":416,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/414\/revisions\/416"}],"wp:attachment":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/media?parent=414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/categories?post=414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/tags?post=414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}