<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@vertical+block@575a0da633e2447595b01f1bdd15665d" data-request-token="72c280dc4d0511f1b4d66b8c55c4de7e" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@c6719d5307bd4aee822fc69250a07430">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@c6719d5307bd4aee822fc69250a07430" data-request-token="72c280dc4d0511f1b4d66b8c55c4de7e" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<h3><strong>Introduction</strong></h3>
<p><span class="cf0">The first lesson of the Python basics session is on performing basic Python commands in a </span><span class="cf0">Jupyter</span><span class="cf0"> Notebook. We will be using a prepared tutorial notebook to guide you through the steps.</span></p>
<h3><span class="cf0"><strong>Set-up prerequisite</strong>s</span></h3>
<p><span class="cf0">The Python basics interactive tutorials use the Digital Earth Africa Sandbox platform. This requires a Digital Earth Africa Sandbox account.</span></p>
<p><span class="cf0">To set up the learning environment, please complete all sections in <strong>Session 1: Introduction</strong> before starting this Python basics module. </span><span class="cf0">Then, follow the instructions below to download the tutorial and open it in the Sandbox.</span></p>
<p><strong><span class="cf0"><span id="docs-internal-guid-c3bd5a0c-7fff-15eb-8791-2779733519cf"><span style="font-size: 14pt; font-family: Inter, sans-serif; color: #434343; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline; white-space-collapse: preserve;">Download the tutorial notebook</span></span></span></strong></p>
<ul>
<ul>
<li><a href="https://learn.digitalearthafrica.org/assets/courseware/v1/7769942de8f765acb19dcc1703746e0c/asset-v1:digitalearthafrica+DEA101+2021+type@asset+block/01_download-jupyter.ipynb" target="_blank">Download the Python basics 1 tutorial notebook</a></li>
</ul>
</ul>
<p><em><span class="cf0"><strong>Note</strong>: </span><span style="font-size: 1em;">Ensure you have created a Training folder in the Sandbox as instructed in Introduction to Digital Earth Africa: Platforms & Sandbox - Part 1 , Session 5: Preparing for the Sandbox.</span></em></p>
<p></p>
<h3><strong>Open in the Sandbox</strong></h3>
<p>1. Download the notebook by clicking the link above.<br />2. On the Sandbox, open the Training folder.<br />3. Click the Upload Files button as shown below. </p>
<p><br /><img height="114" width="400" src="/assets/courseware/v1/4ea6ce25bce944072250cbc0e0f815fb/asset-v1:digitalearthafrica+DEA101+2021+type@asset+block/Image184.png" alt="Image" /></p>
<p><br />4. Select the downloaded notebook using the file browser. Click OK.<br /><span class="cf0">5. The solution notebook will appear in the Training folder. Double</span><span class="cf1">‑</span><span class="cf0">click to open it.</span></p>
<p><em><span class="cf0"><span class="cf0"><strong>Note</strong>: The tutorial notebook should look like the text and code below. However, the tutorial notebook outputs are blank (i.e., no results showing after code cells). Follow the instructions in the notebook to run the cells in the tutorial notebook.</span></span></em></p>
<h3><strong><span class="cf0">Recap: </span><span class="cf0">Jupyter</span><span class="cf0"> Notebooks</span></strong></h3>
<p class="pf0"><span class="cf0">A </span><span class="cf0">Jupyter</span><span class="cf0"> notebook is an interactive environment where you can combine text with Python code that you can modify and execute. The gray cell below contains Python code that you can run. Place the cursor on the Run icon </span><span class="cf1">▶</span><span class="cf0"> in the menu at the top of the notebook to execute the code inside.</span></p>
<p class="pf0"><span class="cf0"><strong>Tip</strong>: Use the shortcut </span><strong><span class="cf0">Shift+Enter</span></strong><span class="cf0"> for running the active cell (where your cursor is). It is a convenient trick that saves you from having to click on the <strong>Run</strong> icon each time.</span></p>
<p class="pf0"><span class="cf0">Select and run the code cell below:<br />______________________________________________________________<br /></span><span style="font-size: 9pt; font-family: 'Roboto Mono', monospace; color: #37474f; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline; white-space-collapse: preserve;"><span style="font-size: 9pt; color: #1967d2; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline;">print</span><span style="font-size: 9pt; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline;">(</span><span style="font-size: 9pt; color: #188038; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline;">"Welcome to the Digital Earth Africa Sandbox!"</span><span style="font-size: 9pt; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline;">)</span><br /><span style="color: #3c3c3c; font-family: 'Open Sans', Verdana, Arial, Helvetica, sans-serif; font-size: 16px; white-space-collapse: collapse;">______________________________________________________________</span></span></p>
<p class="pf0"></p>
<p class="pf0"><span class="cf0">You’ll see that once the code has executed, any output generated by your code will show up just below the cell.<br /><span class="cf0">______________________________________________________________<br /></span></span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 9pt; font-family: 'Roboto Mono',monospace; color: #1967d2; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">print</span><span style="font-size: 9pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">(</span><span style="font-size: 9pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">"3,2,1"</span><span style="font-size: 9pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">)</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 9pt; font-family: 'Roboto Mono',monospace; color: #b80672; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"># Use the hash symbol to comment lines of your code. This does not get executed.</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 9pt; font-family: 'Roboto Mono',monospace; color: #b80672; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"># Use comments to make notes about what your code is doing.</span><span class="cf0"><span style="font-size: 9pt; font-family: 'Roboto Mono', monospace; color: #37474f; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline; white-space-collapse: preserve;"><br /><span style="font-size: 9pt; color: #1967d2; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline;">print</span><span style="font-size: 9pt; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline;">(</span><span style="font-size: 9pt; color: #188038; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline;">"this is fun!"</span><span style="font-size: 9pt; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline;">)</span><br /><span style="color: #3c3c3c; font-family: 'Open Sans', Verdana, Arial, Helvetica, sans-serif; font-size: 16px; white-space-collapse: collapse;">______________________________________________________________</span></span></span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span class="cf0">We can do mathematical computation using Python. Below, we have assigned the sum to a variable. We have chosen to name this variable <span id="docs-internal-guid-2232afe9-7fff-2097-8a01-df694bef62c7"><span style="font-size: 12pt; font-family: 'Roboto Mono', monospace; color: #188038; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline; white-space-collapse: preserve;">result</span></span>.<br /></span></p>
<p class="pf0" style="font-size: 16px;"><span class="cf0">______________________________________________________________<br /></span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #b80672; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"># Set this sum as a variable called result</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">result</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">=</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #c5221f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">999</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">+</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #c5221f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">1</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><b style="font-weight: normal;" id="docs-internal-guid-14868e3d-7fff-f023-e489-dd89b0d299c4"> </b></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #b80672; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"># The output of result is displayed once the computation is completed</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">result</span></p>
<p>______________________________________________________________</p>
<p class="pf0"><span class="cf0">The <span style="color: #339966;"><code>[ ]</code></span> symbol to the left of each code cell describes the state of the cell:</span></p>
<ul>
<ul>
<li><span class="cf0"><code><span style="color: #339966;">[ ]</span></code> means that the cell has not been run yet.</span></li>
<li><span class="cf0"><code><span style="color: #339966;">[*]</span></code> means that the cell is currently running.</span></li>
<li><span class="cf0"><code><span style="color: #339966;">[1]</span></code> means that the cell has finished running and was the first cell run.</span></li>
</ul>
</ul>
<p><span class="cf0">Sometimes, the code that you run in a cell takes a while to compute because it is loading a large dataset or performing complex computations. You’ll notice the number that appears next to the cell. Before the cell is run you’ll see the symbol <code><span style="color: #339966;">[ ]</span></code> meaning that cell has not been executed yet. While a cell is running, it shows the <code><span style="color: #339966;">[*] </span></code></span><span class="cf0">symbol</span><span class="cf0"> and once it has completed running, you’ll see a number representing the number of cells being run, for example <code><span style="color: #339966;">[4]</span></code>. This allows you to keep track of the cells that have been run and their relative order.</span></p>
<p class="pf0"><em><span class="cf0"><strong>Note</strong>: To check whether a cell is currently executing in a </span><span class="cf0">Jupyter</span><span class="cf0"> notebook, inspect the small circle in the top</span><span class="cf1">‑</span><span class="cf0">right of the window. The circle will turn black (“Kernel busy”) when the cell is running, and return to white (“Kernel idle”) when the process is complete.</span></em></p>
<p class="pf0"></p>
<p class="pf0"><span class="cf0">Consider this Python program. Here, we have decided to call our variable <code><span style="color: #993366;">a</span>.<br /><span style="font-family: 'Open Sans', Verdana, Arial, Helvetica, sans-serif;">______________________________________________________________</span><br /></code></span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">a</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">=</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #c5221f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">1</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1967d2; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">print</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">(a)</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><b style="font-weight: normal;" id="docs-internal-guid-d26de0b7-7fff-c960-a05b-9817dc358688"> </b></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">a</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">=</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">a</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">+</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #c5221f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">1</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono', monospace; color: #1967d2; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline; white-space-collapse: preserve;">print</span><span style="font-size: 8pt; font-family: 'Roboto Mono', monospace; color: #37474f; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline; white-space-collapse: preserve;">(a)</span></p>
<p style="font-size: 16px;">______________________________________________________________</p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"></p>
<p class="pf0"><span class="cf0">We can break down this program and execute each line using separate cells.</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><em><span class="cf0"><strong>Note</strong>: Python is case sensitive. The variable <code><span style="color: #800080;">a</span></code> is not the same as <code><span style="color: #800080;">A</span></code>.<br /></span></em></p>
<p class="pf0" style="font-size: 16px;"><span class="cf0"><code><span style="font-family: 'Open Sans', Verdana, Arial, Helvetica, sans-serif;">______________________________________________________________</span><br /></code></span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">a</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">=</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #c5221f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">1</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1967d2; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">print</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">(a)</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><b style="font-weight: normal;" id="docs-internal-guid-1ae02609-7fff-408b-852a-eeab2be855b5"> </b></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">a</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">=</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">a</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">+</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #c5221f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">1</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono', monospace; color: #1967d2; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline; white-space-collapse: preserve;">print</span><span style="font-size: 8pt; font-family: 'Roboto Mono', monospace; color: #37474f; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-variant-position: normal; font-variant-emoji: normal; vertical-align: baseline; white-space-collapse: preserve;">(a)</span></p>
<p style="font-size: 16px;">______________________________________________________________</p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"></p>
<p class="pf0"><span class="cf0">If you run again the first <code><span style="color: #339966;">a</span></code> cell, you’ll see that it returns <code><span style="color: #339966;">2</span></code>, the updated value. This is called ‘global state’, and means that once a variable is declared it is accessible anywhere in the notebook, even in cells above where it has been declared. This is different to traditional programs, which execute sequentially line by line from the top to the bottom. This can be confusing in the beginning, but keep an eye on the number in the brackets <code><span style="color: #339966;">[ ]</span> </code>to see cell execution order.</span></p>
<p class="pf0"><span class="cf0">This also means you can modify all the code in the cells and run them as many times as you want in any order. You can jump back and forth to update variables or re</span><span class="cf1">‑</span><span class="cf0">run the analysis.</span></p>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@vertical+block@79e5211acd674e9d9743c91e65000349" data-request-token="72c280dc4d0511f1b4d66b8c55c4de7e" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@5f31bb1955fc4f41adc884aa4a959dd1">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@5f31bb1955fc4f41adc884aa4a959dd1" data-request-token="72c280dc4d0511f1b4d66b8c55c4de7e" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<p class="pf0" style="padding-left: 30px;"><span class="cf0">1.1 Fill the asterisk line with your name and run the cell.</span></p>
<p class="pf0"><span class="cf0">______________________________________________________________</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #b80672; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"># Fill the ****** space with your name and run the cell.</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><b style="font-weight: normal;" id="docs-internal-guid-bbbf83f6-7fff-f0a4-cb3c-42abace39a5f"> </b></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">message</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">=</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #188038; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">"My name is ******"</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">message<br /><span style="color: rgb(60, 60, 60); font-family: "Open Sans", Verdana, Arial, Helvetica, sans-serif; font-size: 16px; white-space-collapse: collapse;">______________________________________________________________</span></span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span style="color: rgb(60, 60, 60); font-family: "Open Sans", Verdana, Arial, Helvetica, sans-serif; font-size: 16px; white-space-collapse: collapse;"></span></span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"></p>
<p dir="ltr" style="line-height: 1.8; margin-top: 0pt; margin-bottom: 0pt; padding-left: 30px;"><span class="cf0">1.2 You can add new cells to insert new code at any point in a notebook. Click on the + icon in the top menu to add a new cell below the current one. Add a new cell below the next cell, and use it to print the value of variable a.</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span class="cf0">______________________________________________________________</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">a</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">=</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #1c1c1c; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> </span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #c5221f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">365</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #37474f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">*</span><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #c5221f; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">24</span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span class="cf0"> </span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 8pt; font-family: 'Roboto Mono',monospace; color: #b80672; background-color: transparent; font-weight: 400; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"># Add a new cell just below this one. Use it to print the value of variable `a`<br /><span style="color: #3c3c3c; font-family: 'Open Sans', Verdana, Arial, Helvetica, sans-serif; font-size: 16px; white-space-collapse: collapse;">______________________________________________________________</span></span></p>
<p dir="ltr" style="line-height: 1.7999999999999998; margin-top: 0pt; margin-bottom: 0pt;"></p>
<p class="pf0"><span class="cf0"><strong>Question:</strong> Now what happens if you scroll back up the notebook and execute a different cell containing <code><span style="color: #339966;">print(a)</span></code>?</span></p>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@vertical+block@f8e18950275c4d69be8a56a67d73867f" data-request-token="72c280dc4d0511f1b4d66b8c55c4de7e" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@5bdfbe8ec4784851a8dd54ac276799a7">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@5bdfbe8ec4784851a8dd54ac276799a7" data-request-token="72c280dc4d0511f1b4d66b8c55c4de7e" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<p class="pf0"><span class="cf0">Well done on finishing the recap lesson on </span><span class="cf0">Jupyter</span><span class="cf0"> Notebooks. You are now ready to learn about </span><span class="cf0">Numpy</span><span class="cf0">! </span></p>
<p class="pf0"><span class="cf0">Click <strong>Next</strong> to continue.</span></p>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>