[SOLVED] CS python

$25

File Name: CS_python_.zip
File Size: 94.2 KB

5/5 - (1 vote)

QUESTION 1: General Knowledge

10 marks, ~8 minutes

(a) Consider a method of some class that has the following signature:

def mystery(self, m1: int, m2: List[int]) -> Optional[Dict[int, List[int]]]:
# docstring and implementation hidden

On a given call to this method, we observe that the method returns None.

Explain briefly whether returning None implies a violation of each of the
following (e.g., provide and justify your answer for each of these 3 following
concepts):

Does it imply a violation of the Representation Invariant of the class?

TODO: your answer and justification

Does it imply a violation of the precondition of mystery()?

TODO: your answer and justification

Does it imply a violation of the the methods type contract?

TODO: your answer and justification

(b) Consider this piece of code.

1 def blah(lst: List[int]) -> Dict[int, str]:
2 # docstring and implementation hidden
3
4 if __name__ == __main__:
5 a = [1,2,3]
6 foo = blah(a)
7 if 42 in foo:
8 print(Yes)
9else:
10print(No)

Please comment on the possible output of this program, assuming blah() works
correctly.

TODO: your answer here

(c) Consider the following piece of Python code with four lines

1lst = [1, 2, 3]
2lst = lst + [4, 5, 6]
3lst2 = lst
4lst2.append(lst[:])

In each line, how many _objects_ are created in the Python memory model?

TODO: Fill in your answers below.

Line 1:
Line 2:
Line 3:
Line 4:

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS python
$25