Python代写|Final Exam CSC108H5F

本次加拿大代写是一个Python相关的限时测试

You MUST enter the responses to these questions on to the scantron on the back of the cover page of
this test. You may wish to circle your answers here and then check them before entering the responses on
to the scantron if you are using a pen.

Suppose we define

>> H = {“one”: 0, “two”: 2, “three”: 3}

Which of the following will cause an error when typed into the Python interpreter?

A. H[“one”] += 1
B. “four” in H
C. H[2] = {“two”}
D. H.get(“five”) == 5
E. None of the above.

Suppose we define:

>> xs = “0123456789”

Which string slice would produce the empty string?

A. xs[2:7:5]
B. xs[-2:-7:-1]
C. xs[2:7:1][4:5:1]
D. xs[4:-5:-1]
E. None of the above.

What is the best description for the following function?

def mystery(xs):
… k = -1
… for x in xs:
… k += 1
… if xs[k] != x:
… return False
… return True

A. Mystery checks if all members of a list are the same.
B. Mystery checks if all members of a list are different.
C. Mystery always returns True when given a list.
D. Mystery always returns False when given a list.
E. None of the above.

Suppose we type the following code into the Python interpreter:

>> class Point():
… def __init__(self, x: int, y: int):
… self.x = x
… self.y = y

… def __str__(self):
… return ‘({},{})’.format(self.x, self.y)
>>> P = Point(2,3)
>>> Q = Point(2,3)

Which of the following will evaluate to False?

A. type(P) == type(Q)
B. P == Q
C. P.x < Q.y
D. str(P) == str(Q)
E. None of the above.