Add lesson 9: Modules and pip

Mira Kovac 1 year ago
parent b8dc0c1ee7 commit b19220d114ef8052fa4bd0b4a94d6cd47fd99966
4 changed files with 35 additions and 0 deletions
+19-0lessons/09-modules-and-pip/README.md ADDED
@@ -0,0 +1,19 @@
1+# Lesson 9: Modules and pip
2+
3+We look at modules and pip the way working developers use it, with examples you can change and run right away.
4+
5+Full lesson: [https://glibcode.net/courses/python-basics/lessons/9](https://glibcode.net/courses/python-basics/lessons/9)
6+
7+## Files
8+
9+- `modules_demo.py`: the standard library and a package from pip
10+
11+## Run it
12+
13+```sh
14+python3 modules_demo.py
15+```
16+
17+## Exercises
18+
19+See [exercises.md](exercises.md). Ask in the forum once you've tried.
+5-0lessons/09-modules-and-pip/exercises.md ADDED
@@ -0,0 +1,5 @@
1+# Exercises: lesson 9
2+
3+1. Break the example on purpose: delete a bracket or misspell a name. Read the error message. Which line does it point to?
4+2. Combine this lesson with the previous one: use something from both in a small program of your own.
5+3. Add a comment above each block explaining what it does, in your own words.
+10-0lessons/09-modules-and-pip/modules_demo.py ADDED
@@ -0,0 +1,10 @@
1+import random
2+from datetime import date
3+
4+import requests # pip install -r requirements.txt
5+
6+print("Today is", date.today().strftime("%A"))
7+print("Dice:", random.randint(1, 6))
8+
9+r = requests.get("https://api.github.com/zen", timeout=10)
10+print("Zen of the day:", r.text)
+1-0lessons/09-modules-and-pip/requirements.txt ADDED
@@ -0,0 +1 @@
1+requests==2.32.3