diff --git a/exercises/Exercise 2a Local imports.md b/exercises/Exercise 2a Local imports.md new file mode 100644 index 0000000..5bf7ed5 --- /dev/null +++ b/exercises/Exercise 2a Local imports.md @@ -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? diff --git a/exercises/Exercise 2b Unprotected code.md b/exercises/Exercise 2b Unprotected code.md new file mode 100644 index 0000000..57ed751 --- /dev/null +++ b/exercises/Exercise 2b Unprotected code.md @@ -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? diff --git a/materials/part2_local_imports.pptx b/materials/part2_local_imports.pptx index 05107a9..f7b657f 100644 Binary files a/materials/part2_local_imports.pptx and b/materials/part2_local_imports.pptx differ