You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: laboratory/docs/chapter/05.md
+17-17Lines changed: 17 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,11 +5,11 @@
5
5
**What is it about?**
6
6
7
7
* The process of defining something in terms of itself
8
-
* In python this happens when a function calls itself
8
+
* In Python, this happens when a function calls itself
9
9
10
10
**Why do we need it?**
11
11
12
-
* The code look clean and elegant
12
+
* The code looks clean and elegant
13
13
* A complex task is broken down into simpler sub-problems
14
14
* Some data structures like trees are easier to explore using recursion
15
15
@@ -30,10 +30,10 @@ print(factorial_recursive(5))
30
30
31
31
## Reading and writing files
32
32
33
-
* In python, we can read external files and create/write new files with content inside
34
-
* We need to provide the location of the file inside our system: path to the file. If the path is in the current working directory, you can just provide the filename <codeclass="py">myfile.txt</code>. If not then you have to provide the path of the file <codeclass="py">DIRECTORY_NAME/myfile.txt</code>. We have two types of paths
35
-
**Absolute file path:* are notated by a leading forward slash or drive label. The path starts from the root of the file system. E.g. <codeclass="py">/DIRECTORY_1/MY_PROJ_DIRECTORY/MY_PROJ_FILES/myfile.txt</code>
36
-
* Relative file path:</u> are notated by a lack of a leading forward slash. It is interpreted from the perspective of your current working directory. <codeclass="py">MY_PROJ_FILES/myfile.txt</code>
33
+
* In Python, we can read external files and create/write new files with content inside
34
+
* We need to provide the location of the file inside our system, i.e., the path to the file. If the path is in the current working directory, you can just provide the filename <codeclass="py">myfile.txt</code>. If not, then you have to provide the path of the file <codeclass="py">DIRECTORY_NAME/myfile.txt</code>. We have two types of paths
35
+
**Absolute file path:* are notated by a leading forward ("/") slash or drive label (e.g., "C:"). The path starts from the root of the file system. E.g. <codeclass="py">/DIRECTORY_1/MY_PROJ_DIRECTORY/MY_PROJ_FILES/myfile.txt</code>
36
+
* Relative file path:</u> are notated by a lack of a leading forward slash or drive label. It is interpreted from the perspective of your current working directory. <codeclass="py">MY_PROJ_FILES/myfile.txt</code>
@@ -52,11 +52,17 @@ with open("files/txt_sample.txt","r") as my_file:
52
52
53
53
## CSV and JSON files
54
54
55
-
A CSV (Comma Separated Values) file is a form of plain text document which uses a particular format to organize tabular information. CSV file format is a bounded text document that uses a comma to distinguish the values
55
+
A comma-separated values (CSV) file is a delimited text file that uses a comma to separate values. Each line of the file is a data record. Each record consists of one or more fields, separated by commas. A CSV file typically stores tabular data (numbers and text) in plain text, in which case each line will have the same number of fields.
Copy file name to clipboardExpand all lines: laboratory/site/chapter/01/index.html
+13-10Lines changed: 13 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -141,20 +141,20 @@ <h2 id="check-if-python-is-already-installed">Check if Python is already install
141
141
In computing, a <ahref="https://en.wikipedia.org/wiki/Shell_(computing)">shell</a> is a user interface for accessing the services of an operating system. It can be a <ahref="https://en.wikipedia.org/wiki/Command-line_interface">command-line interface (CLI)</a> or a <ahref="https://en.wikipedia.org/wiki/Graphical_user_interface">graphical user interface (GUI)</a>. It enables a user to perform several operations, such as file management, installations, running processes, monitoring and configuring an OS. We will use it to install packages and as an interpreter for Python.
142
142
</span></p>
143
143
<h3id="open-the-command-line-interface-cli">Open the Command Line Interface (CLI)</h3>
144
-
<h4id="windows">Windows</h4>
144
+
<h4>Windows</h4>
145
145
<ul>
146
146
<li>Open the Windows menu</li>
147
147
<li>Type <em>"powershell"</em> in the search bar</li>
148
148
<li>Select <strong>Windows PowerShell</strong> from the search results</li>
149
149
</ul>
150
-
<h4id="macos">macOS</h4>
150
+
<h4>macOS</h4>
151
151
<ul>
152
152
<li>Open the Spotlight search box in the upper right-hand corner</li>
153
153
<li>Type <em>"terminal"</em> in the search bar</li>
154
154
<li>Click on <strong>Terminal</strong> or just hit return if it is the first result</li>
155
155
</ul>
156
156
<p><spanclass="note">Alternatively, go to the directory <spanclass="dir">Applications/Utility</span> and open <strong>Terminal</strong> application.</span></p>
157
-
<h4id="linux-ubuntu">Linux (Ubuntu)</h4>
157
+
<h4>Linux (Ubuntu)</h4>
158
158
<ul>
159
159
<li>Open the applications drawer</li>
160
160
<li>Type <em>"terminal"</em> or <em>"konsole"</em> in the search bar</li>
@@ -168,9 +168,10 @@ <h3 id="check-the-python-version">Check the Python version</h3>
168
168
<pre><code>python --version
169
169
Python 2.7.3
170
170
</code></pre>
171
+
171
172
<p>Try to type <code>python3 --version</code> (also <code>python3 -V</code> on Windows) in the command line, then press return to check whether you have Python 3 installed, and eventually the last version.</p>
172
173
<h2id="download-and-install-python">Download and install Python</h2>
173
-
<h4id="windows_1">Windows</h4>
174
+
<h4>Windows</h4>
174
175
<ul>
175
176
<li>Go to the <ahref="https://www.python.org/downloads/">Python download page</a></li>
176
177
<li>Click on the download button to get the latest version of <strong>Python</strong></li>
<li>Click on the <strong>Install</strong> button, and wait until the end of the installation</li>
189
190
<li>Finally, go to the command line and try to type <code>python --version</code> (also <code>python3 -V</code>) and press return to check whether you correctly installed Python.</li>
190
191
</ul>
191
-
<h4id="macos_1">macOS</h4>
192
+
<h4>macOS</h4>
192
193
<ul>
193
194
<li>Go to the <ahref="https://www.python.org/downloads/">Python download page</a></li>
194
195
<li>Click on the download button to get the latest version of <strong>Python</strong></li>
195
196
<li>Double-click on the downloaded .pkg file to start the installation</li>
196
197
<li>Follow the step-by-step guidelines</li>
197
198
<li>Finally, go to the command line and try to type <code>python --version</code> (also <code>python3 --version</code> in case you have also Python 2) and press return to check whether you correctly installed Python</li>
198
199
</ul>
199
-
<h4id="linux-ubuntu_1">Linux (Ubuntu)</h4>
200
+
<h4>Linux (Ubuntu)</h4>
200
201
<ul>
201
202
<li>Open the Command Line Interface (Terminal or Console)</li>
202
203
<li>Type <code>sudo apt-get update</code></li>
@@ -216,6 +217,7 @@ <h3 id="play-with-python-in-the-shell">Play with Python in the shell</h3>
<li>Type <code>exit()</code> and press enter to exit from the python interactive mode.</li>
221
223
</ul>
@@ -245,23 +247,23 @@ <h3 id="install-modules-with-pip3">Install modules with pip3</h3>
245
247
</ul>
246
248
<h2id="install-the-editor-visual-studio-code">Install the editor: Visual Studio Code</h2>
247
249
<p>Programming using the shell interpreter is convenient for small tests but impractical for developing complex applications. For this reason, special editors, called <ahref="https://en.wikipedia.org/wiki/Integrated_development_environment">integrated development environments</a> (IDE), are used. For Python, the most widely used IDEs are Visual Studio Code, PyCharm and Atom. We suggest using Visual Studio Code for this course.</p>
248
-
<h4id="windows_2">Windows</h4>
250
+
<h4>Windows</h4>
249
251
<ul>
250
252
<li>Download the <ahref="https://code.visualstudio.com/docs?dv=win">Visual Studio Code installer</a> for Windows.</li>
251
253
<li>Run the downloaded installer (VSCodeUserSetup-{version}.exe). This will only take a minute</li>
252
254
<li>By default, VS Code is installed under <spanclass="dir">C:\users{username}\AppData\Local\Programs\Microsoft VS Code</span></li>
253
255
</ul>
254
256
<p><spanclass="note"><strong>Note:</strong> .NET Framework 4.5.2 or higher is required for VS Code. If you are using Windows 7, make sure you have at least <ahref="https://www.microsoft.com/download/details.aspx?id=42643">.NET Framework 4.5.2</a> installed. You can check your version of .NET Framework using this command, <code>reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\full" /v version</code> from a command prompt.</span></p>
255
257
<p><spanclass="note"><strong>Note:</strong> you can find more details at <ahref="https://code.visualstudio.com/docs/setup/windows">https://code.visualstudio.com/docs/setup/windows</a></span></p>
256
-
<h4id="macos_2">macOS</h4>
258
+
<h4>macOS</h4>
257
259
<ul>
258
260
<li>Download <ahref="https://go.microsoft.com/fwlink/?LinkID=534106">Visual Studio Code</a> for macOS.</li>
259
261
<li>Open the browser's download list and locate the downloaded archive.</li>
260
262
<li>Extract the contents of the downloaded archive. (usually with a double-click)</li>
261
263
<li>Drag <strong>Visual Studio Code.app</strong> to the Applications folder, making it available in the macOS Launchpad.</li>
262
264
</ul>
263
265
<p><spanclass="note"><strong>Note:</strong> you can find more details at <ahref="https://code.visualstudio.com/docs/setup/mac">https://code.visualstudio.com/docs/setup/mac</a></span></p>
264
-
<h4id="linux">Linux</h4>
266
+
<h4>Linux</h4>
265
267
<p>For Debian/Ubuntu based distributions, download and install the <ahref="https://go.microsoft.com/fwlink/?LinkID=760868">.deb package (64-bit)</a>, either through the graphical software center if it's available, or through the command line with: <code>sudo apt install ./<file>.deb</code></p>
266
268
<p><spanclass="note"><strong>Note:</strong> you can find more details and guidelines for other linux distributions at <ahref="https://code.visualstudio.com/docs/setup/linux">https://code.visualstudio.com/docs/setup/linux</a></span></p>
267
269
<h2id="create-and-run-a-python-script-in-visual-studio-code">Create and run a Python script in Visual Studio Code</h2>
@@ -288,8 +290,9 @@ <h3 id="create-and-run-the-first-python-script">Create and run the first Python
0 commit comments