adds and edits exercises

This commit is contained in:
Pamela Hathway 2024-08-23 19:17:28 +02:00
parent 35d84965e1
commit e082761458
4 changed files with 105 additions and 31 deletions

View file

@ -20,7 +20,7 @@ Retrival practice in "basic" importing.
def make_example_potion(student_name="ASPP student"): def make_example_potion(student_name="ASPP student"):
my_potion = potion_class.Potion(student_name=student_name) my_potion = potion_class.Potion(student_name=student_name)
# Set up your old kettle and light an eternal flame underneath it. # Set up your old kettle and light an eternal flame underneath it.
my_potion.setup(container=containers.old_kettle) my_potion.setup(container=containers.old_kettle, heat_source="eternal_flame")
# Simmer for 5 hours. # Simmer for 5 hours.
cooking.simmer(my_potion, duration=5) cooking.simmer(my_potion, duration=5)
print(f"You successfully ran make_example_potion, {student_name}, well done :).") print(f"You successfully ran make_example_potion, {student_name}, well done :).")

View file

@ -0,0 +1,62 @@
## Exercise 4: 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
- Create a new branch.
- In the `brew_potions.py` file complete the `make_python_expert_potion` function that makes the *Python expert* potion (instructions below).
- In the `if _ name _ == "_ main _"` part, call the function you are editing and
get Professor Snoope to inspect your potion as shown for the example potion.
Calling `inspection_by_snoope` should never give you an error, so you will have to read what Snoope does and says to find out what went wrong.
- Create a pull request.
##### Brewing instructions
Make a new potion called `python_expert` according to these instructions:
```
1. Set up a pewter cauldron and light a fire underneath it
2. Add fish eyes, unicorn hair and tea leaves
3. Let simmer for 2 hours
4. Have snoope inspect the potion (use target_potion='python_expert').
```
Use the `if __name__ =="__main__"` block in `brew_potions.py` to create the `python_expert` potion and call Snoope to inspect the potion by calling `inspection_by_snoope` .
Make sure you actually call the function you are editing and change the **target** potion for Snoope to `"python_expert"`.
-------------
#### Hints
1. If you don't understand the instructions, please lift your hand and we will come to explain.
2. The python expert potion is very similar to the example potion. You may copy that code and
adapt it accordingly.
3. Note that if you copy from the `example_potion()` function, it is missing a crucial step.
You can look at the `Potion()` class in `brewing/potion_class.by` for inspiration
(it has to do with the ingredients).
4. Don't forget to change the name of the potion you want Snoope to check to "python_expert"
when you call the inspection (in if _ name _ == "_ main _" part).
-------------
#### Extra credit
If you look into the code you will see that there is a cooking method that is defined in the code which we have not used.
What happens if you do use it (try both options!) and let Snoope inspect your potion?
Once you are done, reflect on what you did to find out what the cooking method was
- 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,42 @@
## Exercise 5a: 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
```

View file

@ -1,30 +0,0 @@
## Exercise 4: Workflow
#### Goal
Mimic the *write feature**test feature* workflow.
#### Tasks
In the `brew_potions.py` file complete the `make_python_expert_potion` function that makes the *Python expert* potion (instructions below).
Get Professor Snape to inspect your potion as shown for the example potion. Calling `inspection_by_snape` should never give you an error, so you will have to read what Snape does and says to find out what went wrong.
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 on Github.
##### Brewing instructions
Make a new potion called `python_expert` according to these instructions:
```
1. Set up a pewter cauldron and light a fire underneath it
2. Add fish eyes, unicorn hair and tea leaves
3. Let simmer for 2 hours
4. Have Snape inspect the potion (use target_potion='python_expert').
```
Use the `if __name__ =="__main__"` block in `brew_potions.py` to create the `python_expert` potion and call Snape to inspect the potion by calling `inspection_by_snape` . Make sure you actaully call the function you are editing and change the **target** potion for Snape to `"python_expert"`.
Note that if you copy from the `example_potion()` function, it is missing a crucial step. You can look at the `Potion()` class in `brewing/potion_class.by` for inspiration.