Skip to content

Commit 9f41625

Browse files
committed
pokemon list added to laboratory/data
1 parent 606a388 commit 9f41625

15 files changed

Lines changed: 7275 additions & 227 deletions

File tree

laboratory/data/netflix_titles.csv

Lines changed: 6237 additions & 0 deletions
Large diffs are not rendered by default.

laboratory/data/pokemon_list.csv

Lines changed: 801 additions & 0 deletions
Large diffs are not rendered by default.

laboratory/docs/chapter/05.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
**What is it about?**
66

77
* 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
99

1010
**Why do we need it?**
1111

12-
* The code look clean and elegant
12+
* The code looks clean and elegant
1313
* A complex task is broken down into simpler sub-problems
1414
* Some data structures like trees are easier to explore using recursion
1515

@@ -30,10 +30,10 @@ print(factorial_recursive(5))
3030

3131
## Reading and writing files
3232

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 <code class="py">myfile.txt</code>. If not then you have to provide the path of the file <code class="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. <code class="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. <code class="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 <code class="py">myfile.txt</code>. If not, then you have to provide the path of the file <code class="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. <code class="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. <code class="py">MY_PROJ_FILES/myfile.txt</code>
3737

3838
<span style="color:red">/DIRECTORY_1/MY_PROJ_DIRECTORY/MY_PROJ_FILES/myfile.txt</span>
3939
<span style="color:orange">MY_PROJ_FILES/myfile.txt</span>
@@ -52,11 +52,17 @@ with open("files/txt_sample.txt","r") as my_file:
5252

5353
## CSV and JSON files
5454

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.
5656

5757
```py
5858
import csv
5959

60+
# Reading a CSV file:
61+
with open('files/csv_sample.csv', mode='r') as file:
62+
csvFile = csv.reader(file)
63+
for line in csvFile:
64+
print(line)
65+
6066
# Writing a CSV file:
6167
with open('files/csv_sample.csv', mode='w') as csvfile:
6268
csvwriter = csv.writer(csvfile)
@@ -66,27 +72,21 @@ with open('files/csv_sample.csv', mode='w') as csvfile:
6672
# rows is a list of lists
6773
rows = [["genova","bologna","parma"], ["palermo","napoli","bari"]]
6874
csvwriter.writerows(rows)
69-
70-
# Reading a CSV file:
71-
with open('files/csv_sample.csv', mode='r') as file:
72-
csvFile = csv.reader(file)
73-
for line in csvFile:
74-
print(line)
7575
```
7676

7777
A JSON file is used to transmit data objects consisting of attribute–value pairs and array data types
7878

7979
```py
8080
import json
8181

82+
# Reading a JSON file:
83+
with open('files/json_sample.json', mode='r') as jsonfile:
84+
json_object = json.load(jsonfile)
85+
8286
# Writing a JSON file:
8387
with open('files/json_sample.json', mode='w') as jsonfile:
8488
a_dict = {"Federico":35,"Stefano":22,"Sandro":31}
8589
json.dump(a_dict, jsonfile)
86-
87-
# Reading a JSON file:
88-
with open('files/json_sample.json', mode='r') as jsonfile:
89-
json_object = json.load(jsonfile)
9090
```
9191

9292
## Exercises

laboratory/site/chapter/01/index.html

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,20 @@ <h2 id="check-if-python-is-already-installed">Check if Python is already install
141141
In computing, a <a href="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 <a href="https://en.wikipedia.org/wiki/Command-line_interface">command-line interface (CLI)</a> or a <a href="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.
142142
</span></p>
143143
<h3 id="open-the-command-line-interface-cli">Open the Command Line Interface (CLI)</h3>
144-
<h4 id="windows">Windows</h4>
144+
<h4>Windows</h4>
145145
<ul>
146146
<li>Open the Windows menu</li>
147147
<li>Type <em>"powershell"</em> in the search bar</li>
148148
<li>Select <strong>Windows PowerShell</strong> from the search results</li>
149149
</ul>
150-
<h4 id="macos">macOS</h4>
150+
<h4>macOS</h4>
151151
<ul>
152152
<li>Open the Spotlight search box in the upper right-hand corner</li>
153153
<li>Type <em>"terminal"</em> in the search bar</li>
154154
<li>Click on <strong>Terminal</strong> or just hit return if it is the first result</li>
155155
</ul>
156156
<p><span class="note">Alternatively, go to the directory <span class="dir">Applications/Utility</span> and open <strong>Terminal</strong> application.</span></p>
157-
<h4 id="linux-ubuntu">Linux (Ubuntu)</h4>
157+
<h4>Linux (Ubuntu)</h4>
158158
<ul>
159159
<li>Open the applications drawer</li>
160160
<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>
168168
<pre><code>python --version
169169
Python 2.7.3
170170
</code></pre>
171+
171172
<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>
172173
<h2 id="download-and-install-python">Download and install Python</h2>
173-
<h4 id="windows_1">Windows</h4>
174+
<h4>Windows</h4>
174175
<ul>
175176
<li>Go to the <a href="https://www.python.org/downloads/">Python download page</a></li>
176177
<li>Click on the download button to get the latest version of <strong>Python</strong></li>
@@ -188,15 +189,15 @@ <h4 id="windows_1">Windows</h4>
188189
<li>Click on the <strong>Install</strong> button, and wait until the end of the installation</li>
189190
<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>
190191
</ul>
191-
<h4 id="macos_1">macOS</h4>
192+
<h4>macOS</h4>
192193
<ul>
193194
<li>Go to the <a href="https://www.python.org/downloads/">Python download page</a></li>
194195
<li>Click on the download button to get the latest version of <strong>Python</strong></li>
195196
<li>Double-click on the downloaded .pkg file to start the installation</li>
196197
<li>Follow the step-by-step guidelines</li>
197198
<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>
198199
</ul>
199-
<h4 id="linux-ubuntu_1">Linux (Ubuntu)</h4>
200+
<h4>Linux (Ubuntu)</h4>
200201
<ul>
201202
<li>Open the Command Line Interface (Terminal or Console)</li>
202203
<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>
216217
<pre><code>&gt;&gt;&gt; print(&quot;Hello world&quot;)
217218
Hello World
218219
</code></pre>
220+
219221
<ul>
220222
<li>Type <code>exit()</code> and press enter to exit from the python interactive mode.</li>
221223
</ul>
@@ -245,23 +247,23 @@ <h3 id="install-modules-with-pip3">Install modules with pip3</h3>
245247
</ul>
246248
<h2 id="install-the-editor-visual-studio-code">Install the editor: Visual Studio Code</h2>
247249
<p>Programming using the shell interpreter is convenient for small tests but impractical for developing complex applications. For this reason, special editors, called <a href="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-
<h4 id="windows_2">Windows</h4>
250+
<h4>Windows</h4>
249251
<ul>
250252
<li>Download the <a href="https://code.visualstudio.com/docs?dv=win">Visual Studio Code installer</a> for Windows.</li>
251253
<li>Run the downloaded installer (VSCodeUserSetup-{version}.exe). This will only take a minute</li>
252254
<li>By default, VS Code is installed under <span class="dir">C:\users{username}\AppData\Local\Programs\Microsoft VS Code</span> </li>
253255
</ul>
254256
<p><span class="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 <a href="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>
255257
<p><span class="note"><strong>Note:</strong> you can find more details at <a href="https://code.visualstudio.com/docs/setup/windows">https://code.visualstudio.com/docs/setup/windows</a></span></p>
256-
<h4 id="macos_2">macOS</h4>
258+
<h4>macOS</h4>
257259
<ul>
258260
<li>Download <a href="https://go.microsoft.com/fwlink/?LinkID=534106">Visual Studio Code</a> for macOS.</li>
259261
<li>Open the browser's download list and locate the downloaded archive.</li>
260262
<li>Extract the contents of the downloaded archive. (usually with a double-click)</li>
261263
<li>Drag <strong>Visual Studio Code.app</strong> to the Applications folder, making it available in the macOS Launchpad.</li>
262264
</ul>
263265
<p><span class="note"><strong>Note:</strong> you can find more details at <a href="https://code.visualstudio.com/docs/setup/mac">https://code.visualstudio.com/docs/setup/mac</a></span></p>
264-
<h4 id="linux">Linux</h4>
266+
<h4>Linux</h4>
265267
<p>For Debian/Ubuntu based distributions, download and install the <a href="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 ./&lt;file&gt;.deb</code></p>
266268
<p><span class="note"><strong>Note:</strong> you can find more details and guidelines for other linux distributions at <a href="https://code.visualstudio.com/docs/setup/linux">https://code.visualstudio.com/docs/setup/linux</a></span></p>
267269
<h2 id="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
288290
<!-- <button class="toggle-solution btn btn-light" onclick="toggle_click(this,'sol_1')">Show solution</button>s
289291
```{.python .code-overflow-wrap .solution-code #sol_1}-->
290292

291-
<pre><code class="language-py">print(&quot;Hello World !!&quot;)
293+
<pre><code class="py">print(&quot;Hello World !!&quot;)
292294
</code></pre>
295+
293296
<ul>
294297
<li>Run the script by clicking on the menu arrow near the run button and selecting <strong>Run Python File in Terminal</strong><br />
295298
<img src="../img/vsc_run.png"></li>

0 commit comments

Comments
 (0)