adds 2025 materials

This commit is contained in:
Pamela Hathway 2025-07-20 22:10:03 +02:00
commit e85b3b21ca
23 changed files with 378 additions and 0 deletions

View file

@ -0,0 +1,34 @@
## Exercise 1a: Local importing
#### Goal
Retrival practice in "basic" importing.
#### Preparation
(none)
#### Tasks
We are simulating having code in one folder and calling the code from the folder above.
0. Create a file in the `src/` folder called `daily_menu.py` and copy the code below
into it.
```python
def todays_special():
pizza_margherita = make_margherita_pizza()
schorle = make_apfelschorle()
print("Today's special is ready! Buon Appetito!")
return pizza_margherita, schorle
pizza, drink = todays_special()
```
1. Figure out what import statements are missing, either by visual inspection or
by running the code and seeing what does. Add the missing import statements at
the top of the file. You may need to inspect the files in `src/italianfood/`.
2. Run `daily_menu.py`. Did it work?

View file

@ -0,0 +1,24 @@
## Exercise 1b: Unprotected code
#### Goal
Investigate what happens when importing from modules with "unprotected" code.
#### Preparation
(none)
#### Tasks
0. Create a file in the `src/` folder called `unprotectd_code.py`.
1. Add a line in `unprotectd_code.py` that imports the `todays_special` function from `daily_menu.py`.
2. **BEFORE YOU EXECUTE THE FILE**. Discuss with your partner what you think will happen when you run `unprotectd_code.py`.
3. Run `unprotectd_code.py`. Does your prediction match reality?
4. (optional, for those who know) Discuss with your partner:
* Why did this behaviour occur?
* Why is it not good?
* What can you do to "fix" the behaviour?

View file

@ -0,0 +1,27 @@
## Exercise 2: Editable installation workflow
#### Goal
Experience that working with an editable installation does not change how you interact with your code.
This is supposed to be easy and fun, so run the inspection often and make mistakes with the potion.
Use your git skills to commit the changes you made to a new branch, and create a pull request.
#### Tasks
- In the `make_pizzas.py` file add another function that makes your favourite pizza.
Be creative with your toppings :).
- Call this function from different places in your code
- in `make_pizzas.py` call your function in the if __name__ == "__main__" part
- add it to the tasting menu in the `scripts/run_pizza_restaurant.py` file
- replace the margherita pizza in the `src/daily_menu.py` file with your pizza
-------------
#### Extra credit
Once you are done, reflect on what you did to find out where the function making the pizza was and how it worked
- Where did you look, why did you look there first?
- How did you figure out what it does? What part of the function did you read first?
- Did it work on your first try? If not, how did you try to fix it - trial and error or read documentation?

View file

@ -0,0 +1,45 @@
## Exercise 4: PEP8
#### Goal
Get you familiar with some of the fun facts hidden in the PEP8 guide.
#### Preparation
(none)
#### Tasks
0. Navigate to [PEP8](https://peps.python.org/pep-0008/).
1. Depending on your assigned letter, answer the questions in the corresponding
set below. Feel to tackle the questions out of order. You can also split the
questions between your pair, but be you must leave time to discuss the answers
together.
##### Set A
1. What should you use instead of if y == None?
2. If you have an acronym in camel case, should you capitalize the first letter
only or the whole acronym?
3. How should you check if a variable equals False?
4. What is important about how underscores work with variable names? What happens
if I put an underscore after a variable? One before? Two before?
5. How many spaces should you use after a period in a comment?
##### Set B
1. What are the capitalization guidelines for classes, functions, and variables?
Give examples.
2. How should you check if a path ends in .txt?
3. What is the difference between mixed case, camel case, and snake case?
4. How should you indicate block comments?
5. What are the whitespace rules around operators? Give several examples.
##### Set C
1. If I need to import os, sys, numpy, matplotlib, and a local module called
_utils.py, what does my import block look like?
2. How many blank lines go before a function I define at the top of a module? How
many after?
3. Which of these is correct: x[3:4] or x[3 : 4]?
4. Should you use single or double quotes to indicate strings?
5. Give examples of a long line of code and how you can break it onto multiple
lines.

View file

@ -0,0 +1,42 @@
## Exercise 5: Virtual Environments
#### Goal
Create a virtual environment + install a package + see that that package was installed only in environment
#### Tasks
We will use `venv` as our environment manager - while commands might differ, the principles apply to all other package managers as well.
1. Check which Python you are currently using, and which packages are installed. Also check which folders are in the folder you are installing the environment into.
3. Create and activate a new environment.
4. Check again which Python you are using and which packages are installed - are they different?
5. Install a specific version of a package using pip e.g. pandas=1.5.3
6. See that dependencies are also installed (more packages than only pandas appear)
7. Deactivate and delete the environment
8. Check the packages that are installed when no environment is active again (as step 1). Have they changed?
#### Commands in case you get stuck (not in correct order):
```bash
% investigate Python and packages
> which python
> pip freeze
> pip install <package-name>
> pip install <package-name>==0.0.1
% create an environment option 1 (create folder called venv_folder for files related to virtual environment, feel free to change the name)
> cd <path-to-project_folder>
> mkdir venv_folder
> python3 -m venv venv_folder
> source venv_folder/bin/activate
% create an environment option 2
> python3 -m venv <path-to-folder-for-venv>
> source <path-to-folder-for-venv>/bin/activate
% deactivate and delete a venv environment
> deactivate
> rm -rf venv_folder
```