Skip to content

Commit 1430234

Browse files
zmx721joelostblom
andauthored
Quarto mod7 (#79)
* remove files not needed for quarto * add basic environment file * quarto file structure and update style * remove sklearn specific style * update quiz background color * update quiz correctAnswers logic * increase python code block font size in speaker's notes * module 7 * fix pyodide error --------- Co-authored-by: Joel Ostblom <joelostblom@users.noreply.github.com>
1 parent 87b050a commit 1430234

25 files changed

+2426
-1
lines changed

_quarto.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,28 @@ website:
204204
- text: '&nbsp;&nbsp; 6.1. Exercises'
205205
href: modules/module6/module6-23-function_design_questions.qmd
206206
- href: modules/module6/module6-26-what_did_we_just_learn.qmd
207+
- section: "**Module 7: Importing Files and the Coding Style Guide**"
208+
contents:
209+
- href: modules/module7/module7-00-module_learning_outcomes.qmd
210+
- href: modules/module7/module7-01-importing_python_libraries.qmd
211+
- text: '&nbsp;&nbsp; 1.1. Exercises'
212+
href: modules/module7/module7-02-importing_packages.qmd
213+
- href: modules/module7/module7-05-working_with_other_files.qmd
214+
- text: '&nbsp;&nbsp; 2.1. Exercises'
215+
href: modules/module7/module7-06-importin_your_own_functions_quesitons.qmd
216+
- href: modules/module7/module7-08-testing_your_own_functions_with_pytest.qmd
217+
- text: '&nbsp;&nbsp; 3.1. Exercises'
218+
href: modules/module7/module7-09-using_pytest_questions.qmd
219+
- href: modules/module7/module7-12-automatic_style_formatters.qmd
220+
- text: '&nbsp;&nbsp; 4.1. Exercises'
221+
href: modules/module7/module7-13-flake8_and_black.qmd
222+
- href: modules/module7/module7-15-formatting_that_can't_be_fixed_automatically.qmd
223+
- text: '&nbsp;&nbsp; 5.1. Exercises'
224+
href: modules/module7/module7-16-writing_useful_comments.qmd
225+
- href: modules/module7/module7-18-the_python_debugger.qmd
226+
- text: '&nbsp;&nbsp; 6.1. Exercises'
227+
href: modules/module7/module7-19-using_the_python_debugger.qmd
228+
- href: modules/module7/module7-20-what_did_we_just_learn.qmd
207229

208230
# Since we are declaring options for two formats here (html and revealjs)
209231
# each qmd file needs to include a yaml block including which format to use for that file.

environment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ dependencies:
1010
- matplotlib
1111
- jupyter
1212
- quarto=1.6.43
13+
- flake8-nb
14+
- black[jupyter]
15+
- pytest
1316
- pip
1417
- openpyxl
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
format:
3+
html:
4+
page-layout: full
5+
---
6+
7+
# 0. Module Learning Outcomes
8+
9+
::: {.panel-tabset .nav-pills}
10+
11+
## Video
12+
13+
<iframe
14+
class="video"
15+
src="https://www.youtube.com/embed/SbtORPZ2l6w?start=0&end=48&rel=0"
16+
title="Module 7 Video - Module Learning Outcomes"
17+
frameborder="0"
18+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
19+
allowfullscreen
20+
></iframe>
21+
22+
## Slides
23+
24+
<iframe
25+
class="slide-deck"
26+
src="slides/module7_00.html"
27+
></iframe>
28+
29+
:::
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
format:
3+
html:
4+
page-layout: full
5+
---
6+
7+
# 1. Importing Python Libraries
8+
9+
::: {.panel-tabset .nav-pills}
10+
11+
## Video
12+
13+
<iframe
14+
class="video"
15+
src="https://www.youtube.com/embed/cZwBfjQpHTU?start=0&end=172&rel=0"
16+
title="Module 7 Video - Importing Python Libraries"
17+
frameborder="0"
18+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
19+
allowfullscreen
20+
></iframe>
21+
22+
## Slides
23+
24+
<iframe
25+
class="slide-deck"
26+
src="slides/module7_01.html"
27+
></iframe>
28+
29+
:::
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
format: live-html
3+
---
4+
5+
<script src='../../src/quiz.js'></script>
6+
7+
# 1.1. Exercises
8+
9+
## Importing packages
10+
11+
<div id='mcq1'></div>
12+
<script>
13+
generateQuiz(
14+
'mcq1',
15+
'Question 1',
16+
'How would you import a package named <code>numpy</code>?',
17+
{
18+
'<code>import numpy </code>': 'This is the basic way to import a Python package.',
19+
'<code>as np import numpy </code>': 'Unfortunately, this would not import <code>numpy</code>.',
20+
'<code>from numpy import numpy</code>': 'Are you sure you read the slides properly?',
21+
},
22+
'<code>import numpy </code>',
23+
);
24+
</script>
25+
26+
<div id='mcq2'></div>
27+
<script>
28+
generateQuiz(
29+
'mcq2',
30+
'Question 2',
31+
'How would you import <code>numpy</code> if you wanted to refer to it as <code>np</code>?',
32+
{
33+
'<code>as np import numpy </code>': 'This would actually result in an error!',
34+
'<code>Import numpy As np</code>': 'Be careful with capitals. In this case, when you use capitalization, neither <code>Import</code> nor <code>As</code> are Python keywords.',
35+
'<code>import numpy as np </code>': '',
36+
'<code>As np Import numpy </code>': 'This is not the correct way to import, and it uses capitalization on keywords which is incorrect.',
37+
},
38+
'<code>import numpy as np </code>',
39+
);
40+
</script>
41+
42+
## Importing a Package Function
43+
44+
<div id='mcq3'></div>
45+
<script>
46+
generateQuiz(
47+
'mcq3',
48+
'Question 1',
49+
'How would you import the square root function <code>sqrt</code> from the <code>numpy</code> package?',
50+
{
51+
'<code>import sqrt from numpy</code>': 'Maybe try ordering this differently?',
52+
'<code>from numpy import sqrt</code>': '',
53+
'<code>from sqrt import numpy</code>': 'We are importing only the <code>sqrt</code> function from the <code>numpy</code> package.',
54+
'<code>import numpy from sqrt</code>': '<code>sqrt</code> is a single function that we want to import from <code>numpy</code>.',
55+
},
56+
'<code>from numpy import sqrt</code>',
57+
);
58+
</script>
59+
60+
61+
## Importing Packages... Again
62+
63+
**Instructions:**
64+
Running a coding exercise for the first time could take a bit of time for everything to load. Be patient, it could take a few minutes.
65+
66+
**When you see `____` in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.**
67+
68+
_**Make sure you remove the hash (`#`) symbol in the coding portions of this question. We have commented them so that the line won't execute and you can test your code after each step.**_
69+
70+
Ok, so we've seen this `numpy` package, let's actually load in one of the functions and use it! If you are wondering what this package does, don't worry, you'll learn more of this in the next module. `numpy` has a function called `power()`.
71+
72+
**Tasks:**
73+
74+
- Import the `power()` function from the `numpy` package.
75+
- Use the `power()` function to find 7 to the power of 5 and save it in an object named `power7_5` - you may want to use `?power` to see what arguments the function requires.
76+
- Display your results.
77+
78+
```{pyodide}
79+
#| setup: true
80+
#| exercise: importing_packages_again
81+
import pandas as pd
82+
```
83+
84+
```{pyodide}
85+
#| exercise: importing_packages_again
86+
# Import the power() function from the numpy package
87+
____
88+
89+
# Use the power function to find 7 to the power of 5
90+
# Save your solution in an object named `power7_5`
91+
____ = ____
92+
93+
# Display your results
94+
____
95+
```
96+
97+
```{pyodide}
98+
#| exercise: importing_packages_again
99+
#| check: true
100+
from numpy import power
101+
from src.utils import print_correct_msg
102+
103+
assert result == power(7, 5), "Check your result."
104+
print_correct_msg()
105+
```
106+
107+
:::: { .hint exercise="importing_packages_again"}
108+
::: { .callout-note collapse="false"}
109+
110+
## Hint 1
111+
112+
- Are you using `power(7, 5)`?
113+
- Are you importing using `from`?
114+
115+
:::
116+
::::
117+
118+
:::: { .solution exercise="importing_packages_again" }
119+
::: { .callout-tip collapse="false"}
120+
121+
## Fully worked solution:
122+
123+
```{pyodide}
124+
# Import the power() function from the numpy package
125+
from numpy import power
126+
127+
# Use the power function to find 7 to the power of 5
128+
# Save your solution in an object named `power7_5`
129+
power7_5 = power(7, 5)
130+
131+
# Display your results
132+
power7_5
133+
```
134+
135+
:::
136+
::::
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
format:
3+
html:
4+
page-layout: full
5+
---
6+
7+
# 2. Working with Other Files
8+
9+
::: {.panel-tabset .nav-pills}
10+
11+
## Video
12+
13+
<iframe
14+
class="video"
15+
src="https://www.youtube.com/embed/cZwBfjQpHTU?start=176&end=476&rel=0"
16+
title="Module 7 Video - Working with Other Files"
17+
frameborder="0"
18+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
19+
allowfullscreen
20+
></iframe>
21+
22+
## Slides
23+
24+
<iframe
25+
class="slide-deck"
26+
src="slides/module7_05.html"
27+
></iframe>
28+
29+
:::
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
format: html
3+
---
4+
5+
<script src='../../src/quiz.js'></script>
6+
7+
# 2.1. Exercises
8+
9+
## Importing Your Own Functions Questions
10+
11+
<div id='mcq1'></div>
12+
<script>
13+
generateQuiz(
14+
'mcq1',
15+
'Question 1',
16+
'Where do you save your files so you can import them into new Jupyter notebooks?',
17+
{
18+
'<code>.python</code>': 'Not quite but you are on the right track.',
19+
'<code>.py</code>': '',
20+
'<code>.ipynb</code>': 'This is a Jupyter notebook file, not a file to import a function from.',
21+
},
22+
'<code>.py</code>',
23+
);
24+
</script>
25+
26+
<div id='mcq2'></div>
27+
<script>
28+
generateQuiz(
29+
'mcq2',
30+
'Question 2: Is the following statement True or False?',
31+
'You can import files containing functions in a similar way to how you import Python libraries.',
32+
{
33+
'True': 'That’s right! This makes things easy for us.',
34+
'False': 'Note quite, Python uses a similar importing style for libraries and saved scripts.',
35+
},
36+
'True',
37+
);
38+
</script>
39+
40+
## More Importing Your Own Functions Questions
41+
42+
<div id='mcq3'></div>
43+
<script>
44+
generateQuiz(
45+
'mcq3',
46+
'Question 1',
47+
'If I have a file named <code>baking.py</code> containing functions like <code>cake()</code> and <code>scones()</code> and I want to import it into a Jupyter notebook using the alias <code>bake</code>, which of the following would be required?',
48+
{
49+
'<code>import cake from baking</code>': '<code>cake</code> is the function name, not the library.',
50+
'<code>from baking import bake</code>': 'This isn’t quite right. <code>bake</code> is an alias, not a package.',
51+
'<code>import baking as bake</code>': 'This is right!',
52+
'<code>import bake as scone</code>': 'The alias we want to call <code>baking</code> is <code>bake</code>, not <code>scone</code>.',
53+
},
54+
'<code>import baking as bake</code>',
55+
);
56+
</script>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
format:
3+
html:
4+
page-layout: full
5+
---
6+
7+
# 3. Testing Your Own Functions with Pytest
8+
9+
::: {.panel-tabset .nav-pills}
10+
11+
## Video
12+
13+
<iframe
14+
class="video"
15+
src="https://www.youtube.com/embed/cZwBfjQpHTU?start=483&end=779&rel=0"
16+
title="Module 7 Video - Testing Your Own Functions with Pytest"
17+
frameborder="0"
18+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
19+
allowfullscreen
20+
></iframe>
21+
22+
## Slides
23+
24+
<iframe
25+
class="slide-deck"
26+
src="slides/module7_08.html"
27+
></iframe>
28+
29+
:::

0 commit comments

Comments
 (0)