Add lesson 2: Variables and types

Mira Kovac 1 year ago
parent 5d1b657ffc commit 0e9e10c897787065a85f4f13907db0f98ffd5484
3 changed files with 34 additions and 0 deletions
+19-0lessons/02-variables-and-types/README.md ADDED
@@ -0,0 +1,19 @@
1+# Lesson 2: Variables and types
2+
3+This lesson covers variables and types. You'll read a short explanation, try three small exercises and finish with a quiz.
4+
5+Full lesson: [https://glibcode.net/courses/python-basics/lessons/2](https://glibcode.net/courses/python-basics/lessons/2)
6+
7+## Files
8+
9+- `variables.py`: numbers, strings, booleans and converting input
10+
11+## Run it
12+
13+```sh
14+python3 variables.py
15+```
16+
17+## Exercises
18+
19+See [exercises.md](exercises.md). Ask in the forum once you've tried.
+5-0lessons/02-variables-and-types/exercises.md ADDED
@@ -0,0 +1,5 @@
1+# Exercises: lesson 2
2+
3+1. Rewrite the main part so it runs twice with two different inputs, without copying the code.
4+2. Add a check that prints a warning when a result looks wrong (negative, empty, too big).
5+3. Explain the example to someone who hasn't taken the course. Which part was hardest to explain?
+10-0lessons/02-variables-and-types/variables.py ADDED
@@ -0,0 +1,10 @@
1+age = 29
2+height_m = 1.74
3+name = "Sam"
4+is_student = True
5+
6+print(type(age), type(height_m), type(name), type(is_student))
7+
8+# input() always gives you a string: convert it before doing maths
9+years = int(input("How many years from now? "))
10+print(f"In {years} years {name} will be {age + years}.")