Commit b3d5c158 authored by Guido Bordonaro's avatar Guido Bordonaro
Browse files
parents d9da064f e7f401d5
# Python Courses
# Linux week
## Python 101
## Python Introduction
[![latest version](https://img.shields.io/badge/binder-latest%20version-blue)](https://mybinder.org/v2/git/https%3A%2F%2Fgitlab.poul.org%2Fcorsi%2FPython%2Fintro.git/jupyter?filepath=index.ipynb)
[![latest version](https://img.shields.io/badge/binder-latest%20version-blue)](https://mybinder.org/v2/git/https%3A%2F%2Fgitlab.poul.org%2Fcorsi%2Flinux-week%2Fpython/HEAD?labpath=index.ipynb)
[![latest version](https://img.shields.io/badge/starboard-latest%20version-green)](https://starboard.gg/jupystar?url=https%3A%2F%2Fgitlab.poul.org%2Fgubo97000%2Fintro%2F-%2Fraw%2Fjupyter%2Findex.ipynb)
[![latest version](https://img.shields.io/badge/starboard-latest%20version-green)](https://starboard.gg/jupystar?url=https%3A%2F%2Fgitlab.poul.org%2Fcorsi%2Flinux-week%2Fpython%2F-%2Fraw%2Fmaster%2Findex.ipynb)
### Notebooks for edition
- [![latest version](https://img.shields.io/badge/binder-2021%20ed.-blue)](https://mybinder.org/v2/git/https%3A%2F%2Fgitlab.poul.org%2Fcorsi%2FPython%2Fintro/2021?filepath=index.ipynb)
- [![latest version](https://img.shields.io/badge/binder-2021%20it%20ed.-blue)](https://mybinder.org/v2/git/https%3A%2F%2Fgitlab.poul.org%2Fcorsi%2FPython%2Fintro/2021-it?filepath=index.ipynb)
- [![latest version](https://img.shields.io/badge/binder-2020%20ed.-blue)](https://mybinder.org/v2/git/https%3A%2F%2Fgitlab.poul.org%2Fcorsi%2FPython%2Fintro/2020?filepath=index.ipynb)
- [![latest version](https://img.shields.io/badge/binder-2021%20ed.-blue)](https://mybinder.org/v2/git/https%3A%2F%2Fgitlab.poul.org%2Fcorsi%2Flinux-week%2Fpython/2021?labpath=index.ipynb)
%% Cell type:markdown id:exposed-parade tags:
<h1 class="intro_title" style="text-align:center; font-size: 45px;">Python course 2021</h1>
<h2 class="intro_subtitle" style="text-align:center; font-size: 30px;">Python 101</h2>
<h1 class="intro_title" style="text-align:center; font-size: 45px;">Linux Week 2021</h1>
<h2 class="intro_subtitle" style="text-align:center; font-size: 30px;">Python Introduction</h2>
<img class="intro_logo" style="margin:auto; width:400px" src="https://static.poul.org/assets/logo/logo_text_g.svg" alt="POuL logo"/>
<p class="intro_author" style="text-align: center; font-size: 18px;">
Guido Bordonaro &lt;gubo97000@poul.org&gt;<br/>
Guido Bordonaro &lt;gubo97000@poul.org&gt;<br/>
Giovanni Bezzetto &lt;benzosnmilk@poul.org&gt;<br/>
Andrei Tudor &lt;x7upLime@poul.org&gt;<br/>
</p>
%% Cell type:markdown id:00e3afed tags:
# Python
- Ages very well 🐍 Latest version: 3.10.0
......@@ -91,11 +90,10 @@
@greet("hello")
def hello_world():
print("world")
hello_world()
```
%% Cell type:markdown id:42e8c06b tags:
### The modular one
......@@ -112,11 +110,10 @@
print(f"hello, {self.who}")
clss = Class_hello("world")
clss.hello()
```
%% Cell type:markdown id:49c2a540 tags:
### The simple one
......@@ -163,11 +160,10 @@
``` python
x = 12
print(x)
x = "a string"
print(x)
```
%% Cell type:markdown id:169b5d47 tags:
### Duck typing
......@@ -217,12 +213,10 @@
## Order of operations
x = 10
y = 5
print((x % y) + 1 ** 2 / 2) ## What is the result?
```
%% Cell type:markdown id:48686371 tags:
### A program using the things we just demonstrated
......@@ -233,14 +227,14 @@
``` python
basket = 14
print(f"🍎 The basket contains {basket} apples.")
added_apples = 6
basket += added_apples # basket = basket + added_apples
print(f"🍎 {added_apples} apples were added, for a total of {basket} apples.")
print(f"🍎 Sharing them with 3 people would leave {basket % 3} apple in the basket")
print(f"🍎 {added_apples} apples were added, "
f"for a total of {basket} apples.")
print(f"🍎 Sharing them with 3 people would leave "
f"{basket % 3} apple in the basket")
```
%% Cell type:markdown id:c57c59ee tags:
# [Control-Flow](https://docs.python.org/3/tutorial/controlflow.html)
......@@ -271,11 +265,10 @@
print(0 == False)
print(1.1 > 1)
print(2 <= 2)
print(True and not False)
print(True or False)
```
%% Cell type:markdown id:5a2ee7d0 tags:
## CONDITIONAL Execution
......@@ -294,11 +287,10 @@
print("[*] The basket contains 10 apples")
elif basket > 10:
print("[*] The basket contains more than 10 apples")
else:
print("[*] The basket contains less than 10 apples")
```
%% Cell type:code id:82f16964 tags:
``` python
......@@ -306,11 +298,10 @@
if basket == 0:
print("[*] The basket is empty")
else:
print("[*] The basket contains something")
```
%% Cell type:markdown id:9efbb974 tags:
## Execution by ITERATION
......@@ -333,38 +324,34 @@
basket = 4
while basket > 0: #
basket = basket - 1
print(f"Gnam, we now have {basket} 🍏")
print("\nNo more apples :(")
```
%% Cell type:code id:b735e4f5 tags:
``` python
# Multiplication table
i, base = 1, 9
while i <= 10:
print(f"{base} * {i} = {i*base}")
i += 1
```
%% Cell type:code id:4bb34b90 tags:
``` python
for value in ["apples", "bananas", "pears", "turkeys"]:
print(value)
```
%% Cell type:code id:07c05863 tags:
``` python
for i in range(5):
print(f"{i} {'🍎'*i}")
```
%% Cell type:markdown id:2ef8aa5d tags:
## break & continue
......@@ -377,11 +364,10 @@
print(value, end=" ")
if value == "🤬":
print("Error")
break
print("Happy")
```
%% Cell type:code id:f1331407 tags:
``` python
......@@ -389,11 +375,10 @@
print(value, end=" ")
if value == "🤬":
print("Error")
continue
print("Happy")
```
%% Cell type:markdown id:e6120a5b tags:
# Functions
......@@ -420,29 +405,25 @@
``` python
def say_hello():
print("Hello, world!")
say_hello()
say_hello()
```
%% Cell type:code id:b7602820 tags:
``` python
def add_10(number):
number += 10
print(number)
add_10(2)
add_10(1)
# add_10()
# add_10("user")
```
%% Cell type:code id:3d5775fd tags:
``` python
......@@ -468,11 +449,10 @@
add_10(2)
add_10(1)
add_10()
# add_10("user")
```
%% Cell type:code id:bcd3c9c1 tags:
``` python
......@@ -484,14 +464,12 @@
for i in range(1, length + 1):
print(f"{base} x {i} = {base*i}")
print()
tables(2, 4)
tables(8, show_title=True, length=3)
```
%% Cell type:markdown id:9e1c3bae tags:
## [Scope](https://docs.python.org/3/tutorial/classes.html#python-scopes-and-namespaces), or code visibility
......@@ -526,12 +504,10 @@
fun3()
fun1()
fun2()
print(f"🌍: x = {x}")
```
%% Cell type:markdown id:f15f0b15 tags:
# Data Structures
......@@ -688,16 +664,12 @@
<img class="outro_logo" style="width: 20%;" src="https://static.poul.org/assets/logo/logo_g.svg" alt="POuL logo">
<a class="outro_license" style="display: block; margin: 20px auto;" rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" src="https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/by-nc-sa.svg" /></a>
<p class="outro_license_text" style="font-size: 15px; text-align: center;">Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International<br/>
Notebook source code available in <a href="https://gitlab.poul.org/corsi/Python/intro/-/tree/2021">this repo</a></p>
Notebook source code available in <a href="https://gitlab.poul.org/corsi/linux-week/python/-/tree/2021">this repo</a></p>
<p class="outro_author" style="text-align: center; font-size: 16px;">
Guido Bordonaro &lt;gubo97000@poul.org&gt;<br/>
Giovanni Bezzetto &lt;benzosnmilk@poul.org&gt;<br/>
Andrei Tudor &lt;x7upLime@poul.org&gt;<br/>
</p>
%% Cell type:markdown id:5c14cc92 tags:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment