Skip to content

Quarto mod7 #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ website:
- text: '   12.1. Exercises'
href: modules/module1/module1-32-practicing_bar_charts.qmd
- href: modules/module1/module1-34-what_did_we_just_learn.qmd
- section: "**Module 7: Importing Files and the Coding Style Guide**"
contents:
- href: modules/module7/module7-00-module_learning_outcomes.qmd
- href: modules/module7/module7-01-importing_python_libraries.qmd
- text: '   1.1. Exercises'
href: modules/module7/module7-02-importing_packages.qmd
- href: modules/module7/module7-05-working_with_other_files.qmd
- text: '   2.1. Exercises'
href: modules/module7/module7-06-importin_your_own_functions_quesitons.qmd
- href: modules/module7/module7-08-testing_your_own_functions_with_pytest.qmd
- text: '   3.1. Exercises'
href: modules/module7/module7-09-using_pytest_questions.qmd
- href: modules/module7/module7-12-automatic_style_formatters.qmd
- text: '   4.1. Exercises'
href: modules/module7/module7-13-flake8_and_black.qmd
- href: modules/module7/module7-15-formatting_that_can't_be_fixed_automatically.qmd
- text: '   5.1. Exercises'
href: modules/module7/module7-16-writing_useful_comments.qmd
- href: modules/module7/module7-18-the_python_debugger.qmd
- text: '   6.1. Exercises'
href: modules/module7/module7-19-using_the_python_debugger.qmd
- href: modules/module7/module7-20-what_did_we_just_learn.qmd

# Since we are declaring options for two formats here (html and revealjs)
# each qmd file needs to include a yaml block including which format to use for that file.
Expand Down
7 changes: 4 additions & 3 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ dependencies:
- scipy
- matplotlib
- jupyter
- quarto
- quarto=1.6.43
- flake8-nb
- black[jupyter]
- pytest
- pip


1 change: 1 addition & 0 deletions modules/module1/slides/module1_29.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ If we did instead use double square brackets with `pd.value_counts()`, we would
## Saving a dataframe

```{python}
# | eval: false
mfr_freq.to_csv('data/mfr_frequency.csv', index=False)
```

Expand Down
29 changes: 29 additions & 0 deletions modules/module7/module7-00-module_learning_outcomes.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
format:
html:
page-layout: full
---

# 0. Module Learning Outcomes

::: {.panel-tabset .nav-pills}

## Video

<iframe
class="video"
src="https://www.youtube.com/embed/SbtORPZ2l6w?start=0&end=48&rel=0"
title="Module 7 Video - Module Learning Outcomes"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>

## Slides

<iframe
class="slide-deck"
src="slides/module7_00.html"
></iframe>

:::
29 changes: 29 additions & 0 deletions modules/module7/module7-01-importing_python_libraries.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
format:
html:
page-layout: full
---

# 1. Importing Python Libraries

::: {.panel-tabset .nav-pills}

## Video

<iframe
class="video"
src="https://www.youtube.com/embed/cZwBfjQpHTU?start=0&end=172&rel=0"
title="Module 7 Video - Importing Python Libraries"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>

## Slides

<iframe
class="slide-deck"
src="slides/module7_01.html"
></iframe>

:::
136 changes: 136 additions & 0 deletions modules/module7/module7-02-importing_packages.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
format: live-html
---

<script src='../../src/quiz.js'></script>

# 1.1. Exercises

## Importing packages

<div id='mcq1'></div>
<script>
generateQuiz(
'mcq1',
'Question 1',
'How would you import a package named <code>numpy</code>?',
{
'<code>import numpy </code>': 'This is the basic way to import a Python package.',
'<code>as np import numpy </code>': 'Unfortunately, this would not import <code>numpy</code>.',
'<code>from numpy import numpy</code>': 'Are you sure you read the slides properly?',
},
'<code>import numpy </code>',
);
</script>

<div id='mcq2'></div>
<script>
generateQuiz(
'mcq2',
'Question 2',
'How would you import <code>numpy</code> if you wanted to refer to it as <code>np</code>?',
{
'<code>as np import numpy </code>': 'This would actually result in an error!',
'<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.',
'<code>import numpy as np </code>': '',
'<code>As np Import numpy </code>': 'This is not the correct way to import, and it uses capitalization on keywords which is incorrect.',
},
'<code>import numpy as np </code>',
);
</script>

## Importing a Package Function

<div id='mcq3'></div>
<script>
generateQuiz(
'mcq3',
'Question 1',
'How would you import the square root function <code>sqrt</code> from the <code>numpy</code> package?',
{
'<code>import sqrt from numpy</code>': 'Maybe try ordering this differently?',
'<code>from numpy import sqrt</code>': '',
'<code>from sqrt import numpy</code>': 'We are importing only the <code>sqrt</code> function from the <code>numpy</code> package.',
'<code>import numpy from sqrt</code>': '<code>sqrt</code> is a single function that we want to import from <code>numpy</code>.',
},
'<code>from numpy import sqrt</code>',
);
</script>


## Importing Packages... Again

**Instructions:**
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.

**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.**

_**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.**_

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()`.

**Tasks:**

- Import the `power()` function from the `numpy` package.
- 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.
- Display your results.

```{pyodide}
#| setup: true
#| exercise: importing_packages_again
import pandas as pd
```

```{pyodide}
#| exercise: importing_packages_again
# Import the power() function from the numpy package
____

# Use the power function to find 7 to the power of 5
# Save your solution in an object named `power7_5`
____ = ____

# Display your results
____
```

```{pyodide}
#| exercise: importing_packages_again
#| check: true
from numpy import power
from src.utils import print_correct_msg

assert result == power(7, 5), "Check your result."
print_correct_msg()
```

:::: { .hint exercise="importing_packages_again"}
::: { .callout-note collapse="false"}

## Hint 1

- Are you using `power(7, 5)`?
- Are you importing using `from`?

:::
::::

:::: { .solution exercise="importing_packages_again" }
::: { .callout-tip collapse="false"}

## Fully worked solution:

```{pyodide}
# Import the power() function from the numpy package
from numpy import power

# Use the power function to find 7 to the power of 5
# Save your solution in an object named `power7_5`
power7_5 = power(7, 5)

# Display your results
power7_5
```

:::
::::
29 changes: 29 additions & 0 deletions modules/module7/module7-05-working_with_other_files.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
format:
html:
page-layout: full
---

# 2. Working with Other Files

::: {.panel-tabset .nav-pills}

## Video

<iframe
class="video"
src="https://www.youtube.com/embed/cZwBfjQpHTU?start=176&end=476&rel=0"
title="Module 7 Video - Working with Other Files"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>

## Slides

<iframe
class="slide-deck"
src="slides/module7_05.html"
></iframe>

:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
format: html
---

<script src='../../src/quiz.js'></script>

# 2.1. Exercises

## Importing Your Own Functions Questions

<div id='mcq1'></div>
<script>
generateQuiz(
'mcq1',
'Question 1',
'Where do you save your files so you can import them into new Jupyter notebooks?',
{
'<code>.python</code>': 'Not quite but you are on the right track.',
'<code>.py</code>': '',
'<code>.ipynb</code>': 'This is a Jupyter notebook file, not a file to import a function from.',
},
'<code>.py</code>',
);
</script>

<div id='mcq2'></div>
<script>
generateQuiz(
'mcq2',
'Question 2: Is the following statement True or False?',
'You can import files containing functions in a similar way to how you import Python libraries.',
{
'True': 'That’s right! This makes things easy for us.',
'False': 'Note quite, Python uses a similar importing style for libraries and saved scripts.',
},
'True',
);
</script>

## More Importing Your Own Functions Questions

<div id='mcq3'></div>
<script>
generateQuiz(
'mcq3',
'Question 1',
'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?',
{
'<code>import cake from baking</code>': '<code>cake</code> is the function name, not the library.',
'<code>from baking import bake</code>': 'This isn’t quite right. <code>bake</code> is an alias, not a package.',
'<code>import baking as bake</code>': 'This is right!',
'<code>import bake as scone</code>': 'The alias we want to call <code>baking</code> is <code>bake</code>, not <code>scone</code>.',
},
'<code>import baking as bake</code>',
);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
format:
html:
page-layout: full
---

# 3. Testing Your Own Functions with Pytest

::: {.panel-tabset .nav-pills}

## Video

<iframe
class="video"
src="https://www.youtube.com/embed/cZwBfjQpHTU?start=483&end=779&rel=0"
title="Module 7 Video - Testing Your Own Functions with Pytest"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>

## Slides

<iframe
class="slide-deck"
src="slides/module7_08.html"
></iframe>

:::
Loading
Loading