Skip to content

Commit 292c57a

Browse files
authored
08-func.md: move the 'The Old Switcheroo' exercise to 'Extras' (#917)
1 parent 46ccdfb commit 292c57a

File tree

2 files changed

+8
-39
lines changed

2 files changed

+8
-39
lines changed

_episodes/08-func.md

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,11 @@ readable code!
867867
> > ~~~
868868
> > {: .output}
869869
> > `k` is 0 because the `k` inside the function `f2k` doesn't know
870-
> > about the `k` defined outside the function.
870+
> > about the `k` defined outside the function. When the `f2k` function is called,
871+
> > it creates a [local variable]({{ page.root }}/reference.html#local-variable)
872+
> > `k`. The function does not return any values
873+
> > and does not alter `k` outside of its local copy.
874+
> > Therefore the original value of `k` remains unchanged.
871875
> {: .solution}
872876
{: .challenge}
873877
@@ -920,42 +924,6 @@ readable code!
920924
> {: .solution}
921925
{: .challenge}
922926
923-
> ## The Old Switcheroo
924-
>
925-
> Consider this code:
926-
>
927-
> ~~~
928-
> a = 3
929-
> b = 7
930-
>
931-
> def swap(a, b):
932-
> temp = a
933-
> a = b
934-
> b = temp
935-
>
936-
> swap(a, b)
937-
>
938-
> print(a, b)
939-
> ~~~
940-
> {: .language-python}
941-
>
942-
> Which of the following would be printed if you were to run this code?
943-
> Why did you pick this answer?
944-
>
945-
> 1. `7 3`
946-
> 2. `3 7`
947-
> 3. `3 3`
948-
> 4. `7 7`
949-
>
950-
> > ## Solution
951-
> > `3 7` is the correct answer. Initially, `a` has a value of 3 and `b` has a value of 7.
952-
> > When the `swap` function is called, it creates local variables (also called
953-
> > `a` and `b` in this case) and trades their values. The function does not
954-
> > return any values and does not alter `a` or `b` outside of its local copy.
955-
> > Therefore the original values of `a` and `b` remain unchanged.
956-
> {: .solution}
957-
{: .challenge}
958-
959927
> ## Readable Code
960928
>
961929
> Revise a function you wrote for one of the previous exercises to try to make

_extras/extra_exercises.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ or not (yet) added to the main lesson.
2222
> Compare it to:
2323
>
2424
> ~~~
25-
> left, right = [right, left]
25+
> left, right = right, left
2626
> ~~~
2727
> {: .language-python}
2828
>
@@ -44,7 +44,8 @@ or not (yet) added to the main lesson.
4444
> >
4545
> > In the first case we used a temporary variable `temp` to keep the value of `left` before we
4646
> > overwrite it with the value of `right`. In the second case, `right` and `left` are packed into a
47-
> > list and then unpacked into `left` and `right`.
47+
> > [tuple]({{ page.root }}/reference.html#tuple)
48+
> > and then unpacked into `left` and `right`.
4849
> {: .solution}
4950
{: .challenge}
5051

0 commit comments

Comments
 (0)