CS计算机代考程序代写 python “””

“””
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 method’s 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”)
9 else:
10 print(“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

1 lst = [1, 2, 3]
2 lst = lst + [4, 5, 6]
3 lst2 = lst
4 lst2.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:

“””

Leave a Reply

Your email address will not be published. Required fields are marked *