diff --git a/_episodes/08-func.md b/_episodes/08-func.md index d5e9c698c..606d0f349 100644 --- a/_episodes/08-func.md +++ b/_episodes/08-func.md @@ -867,7 +867,11 @@ readable code! > > ~~~ > > {: .output} > > `k` is 0 because the `k` inside the function `f2k` doesn't know -> > about the `k` defined outside the function. +> > about the `k` defined outside the function. When the `f2k` function is called, +> > it creates a [local variable]({{ page.root }}/reference.html#local-variable) +> > `k`. The function does not return any values +> > and does not alter `k` outside of its local copy. +> > Therefore the original value of `k` remains unchanged. > {: .solution} {: .challenge} @@ -920,42 +924,6 @@ readable code! > {: .solution} {: .challenge} -> ## The Old Switcheroo -> -> Consider this code: -> -> ~~~ -> a = 3 -> b = 7 -> -> def swap(a, b): -> temp = a -> a = b -> b = temp -> -> swap(a, b) -> -> print(a, b) -> ~~~ -> {: .language-python} -> -> Which of the following would be printed if you were to run this code? -> Why did you pick this answer? -> -> 1. `7 3` -> 2. `3 7` -> 3. `3 3` -> 4. `7 7` -> -> > ## Solution -> > `3 7` is the correct answer. Initially, `a` has a value of 3 and `b` has a value of 7. -> > When the `swap` function is called, it creates local variables (also called -> > `a` and `b` in this case) and trades their values. The function does not -> > return any values and does not alter `a` or `b` outside of its local copy. -> > Therefore the original values of `a` and `b` remain unchanged. -> {: .solution} -{: .challenge} - > ## Readable Code > > Revise a function you wrote for one of the previous exercises to try to make diff --git a/_extras/extra_exercises.md b/_extras/extra_exercises.md index 8455f864a..027bbb7ac 100644 --- a/_extras/extra_exercises.md +++ b/_extras/extra_exercises.md @@ -22,7 +22,7 @@ or not (yet) added to the main lesson. > Compare it to: > > ~~~ -> left, right = [right, left] +> left, right = right, left > ~~~ > {: .language-python} > @@ -44,7 +44,8 @@ or not (yet) added to the main lesson. > > > > In the first case we used a temporary variable `temp` to keep the value of `left` before we > > overwrite it with the value of `right`. In the second case, `right` and `left` are packed into a -> > list and then unpacked into `left` and `right`. +> > [tuple]({{ page.root }}/reference.html#tuple) +> > and then unpacked into `left` and `right`. > {: .solution} {: .challenge}