4. Homework#

You should submit a single .py file which contains answers to the following questions. Explanations should be formatted as Python comments.

4.1. Question 1#

Complete Exercise 3.1

1 mark for identifying the correct case, 1 mark for writing the function and 2 marks each for three correct and complete explanations.

4.2. Question 2#

Write a function swap_lists(x, y) which swaps any two lists in-place. For example,

>>> a = [1, 2, 3, 4]
>>> b = [5, 6, 7]
>>> swap_lists(a, b)
>>> a
[5, 6, 7]
>>> b
[1, 2, 3, 4]

Explain why it is not possible to write a function swap_strings(x, y) which swaps two strings x and y.

4 marks for a correct function and 1 mark for the explanation.

[Total: 13 marks]