{"id":94,"date":"2010-07-03T15:51:25","date_gmt":"2010-07-03T07:51:25","guid":{"rendered":"http:\/\/cemclinux1.math.uwaterloo.ca\/~cscircles\/wordpress\/"},"modified":"2021-09-01T11:34:28","modified_gmt":"2021-09-01T03:34:28","slug":"0-introduction","status":"publish","type":"page","link":"https:\/\/olescs.hkmu.edu.hk\/python\/","title":{"rendered":"0: Hello! HKMU students!"},"content":{"rendered":"<!-- Please retain this notice and add more notes if you create a new version.<br \/>\nOriginal lesson author: David Pritchard, daveagp@gmail.com, http:\/\/cscircles.ca<br \/>\nLicense: http:\/\/creativecommons.org\/licenses\/by-nc-sa\/3.0\/-->\n<p>This website teaches computer programming. This skill is very useful: with programming you can automate computer tasks, make art and music, interpret and analyze survey results, build tools for other people, create custom websites, write games, examine genetic data, connect people with each other, and the list goes on and on.<\/p>\n<p>A computer <em>program<\/em> is a series of instructions, written in words, numbers and symbols. Just like any spoken sentence is in a human language like English or French, every computer program is in a <em>programming language<\/em>. A few popular programming languages are&nbsp;<strong>Python<\/strong> (what we will teach here), C++, JavaScript and PHP. We have chosen to teach Python since it is both simple enough for beginners and powerful enough to be used by modern companies. All programming languages use the same general principles, so after you know any one language, you can learn others more quickly.<\/p>\n<p>Here is the first line of <strong>Python<\/strong>&nbsp;code in our lessons.<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform0\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox0'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div>This is a sample <strong>Python<\/strong> program. Press the <strong>Run program<\/strong> button to see what it does.<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 32px;'><textarea wrap='off' name='usercode0' id='usercode0'  cols=10 rows=1 readonly='readonly'  style = 'height : 32px;'  class='pyboxCode RO'>\nprint(\"Hello, World!\")<\/textarea><\/div>\n<div id='pbhistory0' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit0' value=' '\/><\/td>\n<\/tr><\/table><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"en-US\"\/><input type=\"hidden\" id=\"inputInUse0\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"0\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"01179f4aed2f85e6c94eabb3cb9a4c48\"\/>\n<div id='pbresults0' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit0\").value = \"Run program\";document.getElementById(\"inputInUse0\").value = \"N\";<\/script>\n<\/p>\n<p>When you run a program you also get to see the <em>output<\/em>. The example program above only has one command, <code>print(\"Hello, World!\")<\/code> and it created one line of output,<\/p>\n<pre>Hello, World!<\/pre><code><\/code>Here is an analysis of this first program:<\/p>\n<ul>\n<li><code>print<\/code> is the name of a Python command, which sends messages to output.<\/li>\n<li>The parentheses <code>()<\/code> after the print command are used to contain what you want to print.<\/li>\n<li>The quote marks <code>\" \"<\/code> are used as a container for the text <code>Hello, World!<\/code> inside. Without quotes, Python would think that <code>Hello<\/code> was meant to be a command. This would be cause an error since no such command exists.<\/li>\n<\/ul>\n<p>You will learn more about the different pieces of a Python program as you progress through these lessons.<\/p>\n<p>Let's see exactly what happens when we leave out the quotes.<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform1\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox1'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div>This Python program will cause an error. Press the <strong>Run program<\/strong> button.<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 32px;'><textarea wrap='off' name='usercode1' id='usercode1'  cols=10 rows=1 readonly='readonly'  style = 'height : 32px;'  class='pyboxCode RO'>\nprint(Hello, World)<\/textarea><\/div>\n<div id='pbhistory1' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit1' value=' '\/><\/td>\n<\/tr><\/table><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"en-US\"\/><input type=\"hidden\" id=\"inputInUse1\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"1\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"215d19d291445e6a35f30de1b9b7f66e\"\/>\n<div id='pbresults1' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit1\").value = \"Run program\";document.getElementById(\"inputInUse1\").value = \"N\";<\/script>\n<\/p>\n<p>Here, the program <em>crashed<\/em>: this means we gave a bad command to the computer, causing an error and forcing it to stop.<\/p>\n<h2>Exercise<\/h2>\n<p>Our first exercise is given below. It asks you to write a program similar to the first one above. Type your program into the box, and when you want to test whether your program correctly performs the task, press the <strong>Run program<\/strong> button. If you don't get it correct on the first try, edit the program and try running it again.<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform2\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox2'>\n<img title='You have not yet completed this problem.' src='https:\/\/olescs.hkmu.edu.hk\/python\/wp-content\/plugins\/pybox\/files\/icon.png' class='pycheck'\/><div class=\"heading\"><span class='type'>Coding Exercise: <\/span><span class='title'>Bonjour<\/span><\/div>Write a program which prints <\/p>\n<pre>Bonjour, tout le monde!<\/pre> (Hint: if you get stuck, copy the <a class=\"hintlink\"  id=\"hintlink3\">first program above<\/a> and then edit it.)<div class=\"helpOuter\" style=\"display: none;\"><div class=\"helpInner\"><div style=\"text-align: center\">You need to create an account and log in to ask a question.<\/div><\/div><\/div><div class='pyboxTextwrap pyboxCodewrap RW resizy'  style='height: 526px;'><textarea wrap='off' name='usercode2' id='usercode2' placeholder='Click on this box and type to enter your code' cols=10 rows=20   class='pyboxCode RW'>\n<\/textarea><\/div>\n<div id='pbhistory2' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit2' value=' '\/><\/td>\n<td><input type='button' name='history' value=\"History\" onclick=\"historyClick(2,'0.bonjour')\" ><\/td>\n<td><input type='button' name='help' value=\"Help\" onclick=\"helpClick(2);\" ><\/td>\n<\/tr><\/table><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"en-US\"\/><input type=\"hidden\" id=\"inputInUse2\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"2\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"79bb681d5a54bb8636b4e26890fe9452\"\/>\n<div id='pbresults2' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit2\").value = \"Run program\";document.getElementById(\"inputInUse2\").value = \"N\";<\/script>\n<\/p>\n<p><em>Tip: you can make the code box look taller by dragging its <a>bottom border<\/a>.<\/em><\/p>\n<p>If you have logged in,<\/p>\n<ul>\n<li>we will save every version of the code that you run;<\/li>\n<li><strong>History<\/strong>&nbsp;shows you all versions you have submitted so far;<\/li>\n<li>and when you visit the site again, the most recent version appears in the editor.<\/li>\n<\/ul>\n<p>Once you get an exercise like this correct, you will see a checkmark <img decoding=\"async\" style=\"vertical-align: -6px;\" src=\"\/wp-content\/plugins\/pybox\/files\/checked.png\" alt=\"\" width=\"24px\" height=\"24px\"> appear in the top right corner of the box. If you are logged in, the Computer Science Circles website will remember which exercises you complete.<\/p>\n<p><table class='pywarn'><tr><td class='pywarnleft'><img src='https:\/\/olescs.hkmu.edu.hk\/python\/wp-content\/plugins\/pybox\/files\/warning.png'\/><\/td><td class='pywarnright'><span> These lessons teach <strong>Python version 3<\/strong>. While our lessons aim to be self-contained, if you decide to search online for other information about Python, be aware that Python version 2 is also commonly used and is incompatible in some ways.   <\/span><\/td><\/table><\/p>\n<p>Once you are ready to go to the next lesson, click the <strong>Next<\/strong> button below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This website teaches computer programming. This skill is very useful: with programming you can automate computer tasks, make art and music, interpret and analyze survey results, build tools for other people, create custom websites, write games, examine genetic data, connect &hellip; <a href=\"https:\/\/olescs.hkmu.edu.hk\/python\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-94","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/olescs.hkmu.edu.hk\/python\/wp-json\/wp\/v2\/pages\/94"}],"collection":[{"href":"https:\/\/olescs.hkmu.edu.hk\/python\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/olescs.hkmu.edu.hk\/python\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/olescs.hkmu.edu.hk\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/olescs.hkmu.edu.hk\/python\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":8,"href":"https:\/\/olescs.hkmu.edu.hk\/python\/wp-json\/wp\/v2\/pages\/94\/revisions"}],"predecessor-version":[{"id":11478,"href":"https:\/\/olescs.hkmu.edu.hk\/python\/wp-json\/wp\/v2\/pages\/94\/revisions\/11478"}],"wp:attachment":[{"href":"https:\/\/olescs.hkmu.edu.hk\/python\/wp-json\/wp\/v2\/media?parent=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}