python-novice-gapminder
python-novice-gapminder copied to clipboard
Fix issue #204: Remove a poorly designed challenge
Fixes issue #204 by simply removing the challenge in question.
:ok: Pre-flight checks passed :smiley:
This pull request has been checked and contains no modified workflow files, spoofing, or invalid commits.
It should be safe to Approve and Run the workflows that need maintainer approval.
Thank you for taking care of this -- I agree that that exercise is poorly designed. However, I'm a bit hesitant on leaving this episode without any exercise. Would it be feasible to modify it so that e.g. it asks a simple question about the scope of variables in a code example like the one there?
How about this?
::::::::::::::::::::::::::::::::::::::: challenge
## Tracing Global Variables
The code block below is a repeat of the example above,
but with a global variable called `temperature` defined
before the `adjust` function definition.
```python
pressure = 103.9
temperature = 294.15 # checkpoint 1
def adjust(t):
temperature = t * 1.43 / pressure
return temperature # checkpoint 2
print('adjusted:', adjust(0.9))
print('temperature after call:', temperature) # checkpoint 3
```
1. Think through the code block line-by-line,
tracing the value of the variables as the program is run.
Fill in the table with the values of variables
called `pressure`, `temperature`, and `t`
at each of the checkpoints (marked with comments in the code block).
Write "undefined" if the value of a variable has not yet been set.
| Checkpoint | `pressure` | `temperature` | `t` |
| ----------| ---------- | ------------- | ----------- |
| 1 | | | |
| 2 | | | |
| 3 | | | |
1. **Before running this code block,** think about what you expect the result to be.
Can you identify which of the options below is correct?
1. A `NameError` again
1. ```output
adjusted: 0.01238691049085659
temperature after call: 294.15
```
1. ```output
adjusted: 0.01238691049085659
temperature after call: 0.01238691049085659
```
1. Now run the code. Did you predict the result correctly?
::::::::::::::: solution
After the global variables are first defined,
their values are not modified by any of the subsequent lines.
No global variable called `t` is ever created outside the `adjust` function,
so this variable remains undefined at all of the checkpoints:
| Checkpoint | `pressure` | `temperature` | `t` |
| ----------| ---------- | ------------- | ----------- |
| 1 | 103.9 | 294.15 | undefined |
| 2 | 103.9 | 294.15 | undefined |
| 3 | 103.9 | 294.15 | undefined |
This means that the output produced by the code block is option 2:
```output
adjusted: 0.01238691049085659
temperature after call: 294.15
```
:::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::