Skip to content

Commit

Permalink
Adding episode 02 solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
wood-chris committed Feb 24, 2024
1 parent dc7b92f commit da6e1af
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions _episodes/02-short-introduction-to-Python.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,15 @@ a_list = [1, 2, 3]
Does the `help()` function confirm this?
>
> > ## Solution
> > ~~~
> > 1. The second value in a_list is replaced with 5.
> > 2. There is an error: TypeError: 'tuple' object does not support item assignment; As a tuple is immutable, it does not support item assignment. Elements in a list can be altered individually.
> > 3. `<class 'tuple'>`; The function tells you that the variable *a_tuple* is an object of the class *tuple*.
> > 4. len() tells us the length of an object. It works the same for both lists and tuples, providing us with the number of entries in each case.
> > 2. There is an error:
> > ~~~
> > TypeError: 'tuple' object does not support item assignment
> > ~~~~
> > {: .language-python}
> > As a tuple is immutable, it does not support item assignment. Elements in a list can be altered individually.
> > 3. `<class 'tuple'>`; The function tells you that the variable *a_tuple* is an object of the class *tuple*.
> > 4. `len()` tells us the length of an object. It works the same for both lists and tuples, providing us with the number of entries in each case.
> {: .solution}
{: .challenge}
Expand Down Expand Up @@ -453,6 +456,28 @@ for key in rev.keys():
> 2. Reassign the value that corresponds to the key `second` so that it no longer
> reads "two" but instead `2`.
> 3. Print the value of `rev` to the screen again to see if the value has changed.
>
> > ## Solution
> > 1.
> > ~~~
> > print(rev)
> > ~~~
> > {: .language-python}
> > ~~~
> > {'first': 'one', 'second': 'two', 'third': 'three'}
> > ~~~
> > {: .output}
> > 2 & 3:
> > ~~~
> > rev['second'] = 2
> > print(rev)
> > ~~~
> > {: .language-python}
> > ~~~
> > {'first': 'one', 'second': 2, 'third': 'three'}
> > ~~~
> > {: .output}
> {: .solution}
{: .challenge}
Expand Down

0 comments on commit da6e1af

Please sign in to comment.