adding exercises and part2 slides
This commit is contained in:
parent
842d09bb55
commit
19a4dde84f
38
exercises/Exercise 2a Local imports.md
Normal file
38
exercises/Exercise 2a Local imports.md
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
## Exercise 2a: Local importing
|
||||||
|
|
||||||
|
#### Goal
|
||||||
|
|
||||||
|
Retrival practice in "basic" importing.
|
||||||
|
|
||||||
|
#### Preparation
|
||||||
|
|
||||||
|
(none)
|
||||||
|
|
||||||
|
#### Tasks
|
||||||
|
|
||||||
|
0. Create a file in the `src/` folder called `make_potion.py` and copy the code below
|
||||||
|
into it.
|
||||||
|
|
||||||
|
```python
|
||||||
|
# ADD IMPORT STATEMENTS HERE!
|
||||||
|
|
||||||
|
|
||||||
|
def make_example_potion(student_name="ASPP student"):
|
||||||
|
my_potion = potion_class.Potion(student_name=student_name)
|
||||||
|
# Set up your old kettle and light an eternal flame underneath it.
|
||||||
|
my_potion.setup(container=containers.old_kettle)
|
||||||
|
# Simmer for 5 hours.
|
||||||
|
cooking.simmer(my_potion, duration=5)
|
||||||
|
print(f"You successfully ran make_example_potion, {student_name}, well done :).")
|
||||||
|
return my_potion
|
||||||
|
|
||||||
|
|
||||||
|
my_name = 'ASPP student'
|
||||||
|
my_potion = make_example_potion(student_name=my_name)
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Figure out what import statements are missing, either by visual inspection or
|
||||||
|
by running the code and seeing what dies. Add the missing import statements at
|
||||||
|
the top of the file. You may need to inspect the files in `src/brewing/`.
|
||||||
|
|
||||||
|
2. Run `make_potion.py`. Did it work?
|
26
exercises/Exercise 2b Unprotected code.md
Normal file
26
exercises/Exercise 2b Unprotected code.md
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
## Exercise 2a: 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 `main.py`.
|
||||||
|
|
||||||
|
1. Add a line in `main.py` that imports the `make_example_potion` function from
|
||||||
|
`make_potion.py`.
|
||||||
|
|
||||||
|
2. **BEFORE YOU EXECUTE THE FILE**. Discuss with your partner what you think will
|
||||||
|
happen when you run `main.py`.
|
||||||
|
|
||||||
|
3. Run `main.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?
|
Binary file not shown.
Loading…
Reference in a new issue