代做CSC 110 Y1F Fall 2024 Quiz 6 - V1代写C/C++程序
- 首页 >> WebFaculty of Arts & Science
Fall 2024 Quiz 6 - V1
CSC 110 Y1F
Question 1. Object Mutation [3 marks]
Part (a) [1 mark]
Consider the code below.
>>> lst = [1, 2, 3]
>>> lst.append([4, 5])
What will lst refer to after the executing every line above? Circle the correct option below.
a) [1, 2, 3, 4, 5]
b) [1, 2, 3, [4, 5]]
c) [1, 2, 3, 4]
d) This will raise an Error since a list can not be appended to a list.
Part (b) [1 mark]
Which functions or operations are most useful for determining if two variables refer to different objects? Select all that apply.
a) type
b) ==
c) is
d) id
Part (c) [1 mark]
Consider the following code:
>>> s = ' CSC110 '
>>> z = s
>>> s = ' CSC110 ' + ' Y '
>>> m = z
>>> z[5] = ' 1 '
Which of the following is true? Select all that apply.
a) z refers to ' CSC111Y '
b) m refers to ' CSC111Y '
c) s and m have the same id after the above code is executed
d) An error is raised when the above code is executed.
Question 2. Object Mutation [5 marks] Consider the function f1:
def f1(s: set, lst: list) -> list:
""" """
...
for element in lst:
s.add(element)
new_list = lst
for element in sorted(s):
new_list.append(element)
return new_list
And suppose we execute the following in the console:
>>> my_list = [0, 1, 2]
>>> my_set = {1, 2, 3}
>>> my_other_list = f1(my_set, my_list)
Part (a) [2 marks]
What value will my_list refer to?
a) [0, 1, 2]
b) [0, 1, 2, 3]
c) [0, 1, 2, 0, 1, 2, 3]
d) [0, 0, 1, 1, 2, 2, 3]
Part (b) [3 marks]
Which expressions below evaluate to True? Select all that apply.
a) my_set == {0, 1, 2, 3}
b) my_set == {0, 1, 2}
c) my_other_list is my_set
d) my_other_list is my_list
e) my_other_list == my_list
f) my_other_list == list(my_set)
Question 3. Memory Model [4 marks]
Below is an object-based memory model diagram showing the state of the memory model at the moment
Part (b) [3 marks]
Complete the following code so it will generate the memory model diagram shown above by putting an expression or statement in each of the three boxes. Do not add in any extra lines or change anything else.
def binoo(stuff: list, i: int) -> None:
stuff[i] =
def toopy(lst: list, add: str) -> None:
binoo(lst[0], 1)
if __name__ == ' __main__ ' : nums = [26, 17, 39]
word = ' hi '
things =
toopy(things, ' ! ' )