Preview Test: CSSE1001/7030 Semester One Final Examination 2020 Test Information Description Instructions Timed Test This test has a time limit of 2 hours and 30 minutes.This test will save and be submitted automatically when the time expires. Warnings appear when half the time, 5 minutes, 1 minute, and 30 seconds remain. [The timer does not appear when previewing this test] Multiple Attempts Not allowed. This Test can only be taken once. Force Completion This Test can be saved and resumed at any point until time has expired. The timer will continue to run if you leave the test. Your answers are saved automatically. CSSE1001/7030. Introduction to Software Engineering. Semester 1 Final Examinations. Materials permitted include 2 blank sheets of A4 paper and a FX82 series calculator or a UQ approved and labelled calculator or a calculator from UQ's list of approved calculators. You are NOT allowed to run any Python software while doing this examination. Answer all questions. For all questions, please choose the most appropriate answer if it appears that more than one option is a potentially correct answer. All coding questions relate to the Python 3 programming language. If an evaluation produces an error of any kind, choose Error as your answer. Different questions may have different numbers of choices. Each question is worth one mark. If you experience any technical difficulties during the exam, talk to your online invigilator via the webcam or chat functions. If the technical trouble cannot be resolved, you should ask for an email (or transcript of the chat) documenting any technical advice provided to support your request for a deferred exam. QUESTION 1 Please use this space to specify any assumptions you have made in completing the exam and which questions those assumptions relate to. You may also include queries you may have made with respect to a particular question, should you have been able to ‘raise your hand’ in an examination room. 0 points Save Answer QUESTION 2 What does the expression (6.1 + 3.2) // 3 evaluate to? 3 3.0 3.1 Error 1 points Save Answer QUESTION 3 What does the expression 3 + 5 % 2 evaluate to? 4 4.0 5.5 0 Error 1 points Save Answer QUESTION 4 What does the expression 11.0 % 3 ** 2 evaluate to? 4.0 Error 2.0 4 2 1 points Save Answer QUESTION 5 What will be returned when (7,3,(6,)) + (9,(5)) is entered into Python? (7, 3, 6, 9, 5) (7, 3, (6,), 9, (5)) (7, 3, (6,), (9, (5))) (7, 3, (6,), 9, 5) None of the other choices are correct 1 points Save Answer QUESTION 6 What does the expression ['ab'] <= ['ba'] evaluate to? Error 'ba' 'ab' False True 1 points Save Answer QUESTION 7 What is the value of a after the following statements are evaluated? x = [1, 'a', '\t bc'.strip()] y = ['d', 'g', 'f'] z = x + y a = z[2] '\tbc' 'bc' Error '\t bcf' '\tbc' 1 points Save Answer QUESTION 8 What is the result of max(2,4) < min(5,[6,3][1]) ? True False Error None of the other choices are correct 1 points Save Answer QUESTION 9 What is the value of x after the following statements are evaluated? x = [23, True, False] y = x y[2] = 46 x[1] = 7 [23, 7, False] [23, 7, 46] Error None of the other choices 1 points Save Answer QUESTION 10 After the assignment s1 = "Ode to Programming", which of the following statements assigns 'rog' to s2? s2=s1[8:11] s2=s1[8:10] s2 = s1[-7:-10] s2 = s1[-10:-7] More than one of the other options are correct 1 points Save Answer QUESTION 11 Given the assignment s1 = "Ode to Programming", what will the value of s2 be after the following command is entered? s2=s1[3:11:4] s2 = 'e ' s2 = ' Pr' s2 = ' P' None of the other choices are correct 1 points Save Answer QUESTION 12 What will be in sum after the following loop has completed executing? sum='' for e,f in ('ab','cd'): sum+=2*e+f ('ababcd') 'ababcd' 'aabccd' Error None of the other choices are correct 1 points Save Answer QUESTION 13 What will be printed after the following code is executed: x = input("Please enter a two digit number: ") x1 = int(x) x1 = x1[0] print("The first digit is:", x1) The first digit is: 1 The first digit is: 15 An Error message The first digit is: 1 points Save Answer QUESTION 14 After executing the code below, what would be the contents of a? a={1:"s",2:"t",3:"r"} b={4:"i",5:"n"} a.update({6:b.get(5)}) {1: 's', 2: 't', 3: 'r'} {1: 's', 2: 't', 3: 'r', 6: 'n'} {} Error None of the other choices are correct 1 points Save Answer QUESTION 15 What is the value of d2 after the following statements are evaluated? d = {1:'a', 2:'b', 3:'c'} d2 = d.update({5:['def']}) {1: 'a', 2: 'b', 3: 'c', 5: 'def'} {1: 'a', 2: 'b', 3: 'c', 5: ['def'] Error None {1:'a', 2:'b', 3:'c'} 1 points Save Answer QUESTION 16 What is the value of y after the following code is executed? def g(y): y = y+25 return y y=40 g(y) 65 40 None Error 1 points Save Answer QUESTION 17 The following recursive function definition is used in this question and the next one. def g(x) : if x == 1 : return 1 x -=1 return g(x-1)*x What will the function call g(3) return? 2 RecursionError will be raised due to maximum recursion depth being exceeded 6 4 1 points Save Answer QUESTION 18 What will the function call g(2) return? 0 -1 1 RecursionError will be raised due to maximum recursion depth being exceeded. 1 points Save Answer QUESTION 19 The following class and method definitions are used for this and the following 4 questions. class A(object) : def __init__(self, x) : self._x = x+1 def m1(self, x) : return self.m2(x) * 3 def m2(self, x) : return x + 2 class B(A) : def m2(self, y) : return self._x + y class C(B) : def __init__(self, x, y) : super().__init__(x) self._y = y+1 def m1(self, x) : return self._x + self._y class D(B) : def __init__(self, x, y) : super().__init__(x) self._x += y self._y = y-1 def m1(self, y) : return self._y + y def m2(self, x) : return super().m2(x) + x a = A(2) b = B(1) c = C(1, 2) d = D(1, 1) What does a.m1(1) return? 7 9 11 13 None of the other choices are correct 1 points Save Answer QUESTION 20 What does b.m1(1) return? 5 7 9 11 None of the other choices are correct 1 points Save Answer QUESTION 21 What does c.m2(2) return? 1 2 3 4 None of the other choices are correct 1 points Save Answer QUESTION 22 What does d.m1(2) return? -1 0 1 2 None of the other choices are correct 1 points Save Answer QUESTION 23 What does d.m2(2) return? 5 6 7 8 None of the other choices are correct 1 points Save Answer QUESTION 24 What is the value of z after the following has been evaluated? g = lambda u,v: u+v vs = 'trot' z = [g(u,v) for u in 'same' if u not in 'amps' for v in vs] ['st', 'sr', 'so', 'st', 'at', 'ar', 'ao','at', 'mt', 'mr', 'mo', 'mt'] ['et', 'er', 'eo', 'et'] [] None of the above choices are correct 1 points Save Answer QUESTION 25 After running the following code: import random xs=[1,2,3,4] new_list=[(x,random.random()) for x in xs] new_list.sort() z=[ (y,y) for y,x in new_list] which of the following represents the most plausible contents of z? [(1, 0.3656826997131658), (2, 0.4789711218283632), (3, 0.20367358828920812), (4, 0.4651024789182844)] [(0.23845323656036166, 2), (0.5411763744080424, 4), (0.7368067435015173, 3), (0.9585633916983842, 1)] [(0.7070150251404196, 0.7070150251404196), (0.9635956493452444, 0.9635956493452444), (0.5960013756836279, 0.5960013756836279), (0.9623962721301965, 0.9623962721301965)] [(1, 1), (2, 2), (3, 3), (4, 4)] Error 1 points Save Answer QUESTION 26 The following partial definition of a SwimRecord class is used in this and the following two questions. class SwimRecord(object) : def __init__(self, name, club) : """Parameters: name(str): swimmer’s name club(str): swimmer’s club self._swim_record(dict): Data record to store swim meets and swim times. The key is the name of the swim meet; the value is the time recorded for each swim meet""" self._name = name self._club = club self._swim_record = {} def update_swim_record(self, new_results: dict) : """Add results from 'new_results' into record.""" ## code block 1 ## def get_swim_results(self, swim_meet: str) : """Get swim results.""" return self._swim_record.get(swim_meet,'Err') def get_swim_times(self) : """Return all swim times in a list""" ## code block 2 ## What is the required code for ## code block 1 ##? self._swim_record += new_results self._swim_record.update(new_results) self._swim_record.append(new_results) None of the other code blocks are correct. 1 points Save Answer QUESTION 27 What is the required code for ## code block 2 ## ? return [j for i,j in self._swim_record.items()] return self._swim_record return list(self._swim_record.keys()) return swim_record.update(self) More than one of the other choices are correct 1 points Save Answer QUESTION 28 After the assignment z='ministry of silly walks' what does the expression '----'.join(z.split('silly')) evaluate to? ['ministry', 'of', '----', 'walks'] '----silly' 'ministry of ---- walks' None of the other choices are correct 1 points Save Answer QUESTION 29 The next 3 questions refer to the following denition that is missing three lines of code. The function get_column_sums below reads data from a CSV (Comma Separated Values) le and returns the list of sums for each column. We assume the le contains rows of oating point numbers separated by commas (and possibly including spaces) and each row has the same number of oats. Below is an example of such a le and the result of applying the function to that le.The following is an example of a data le (values.txt). 1.2, 1 ,2.3, 1.4, 0.1 0.7,1.5, 1.2, 2.4, 0.1 2.1,0.7, 1.4, 2.0, 0.1 >>> get_column_sums('values.txt') [4.0, 3.2, 4.9, 5.8, 0.3] >>> The denition of the get_column_sums function with three missing lines and the result of applying the completed function to the le is given below. def get_column_sums(lename): fd = open(lename, 'r') data = [] for line in fd: parts = line.split(',') line_data = [] for p in parts: ## line 1 ## data.append(line_data) column_sums = [] for index in range(len(data[0])): colsum = 0 for row in range(len(data)): ## line 2 ## ## line 3 ## return column_sums What is the required code for ## line 1 ##? line_data.append(p) line_data.append(oat(p.strip())) line_data.extend(p) line_data.extend(oat(p.strip())) More than one of the other options is correct. 1 points Save Answer QUESTION 30 What is the required code for ## line 2 ##? colsum = data[index][row] colsum = data[row][index] colsum += data[index][row] colsum += data[row][index] More than one of the other opons is correct 1 points Save Answer QUESTION 31 What is the required code for ## line 3 ##? column_sums.append(colsum) column_sums.extend(colsum) column_sums + colsum column_sums + [colsum] More than one of the other opons is correct 1 points Save Answer QUESTION 32 The next two question relate to the following partial denitions. In a GUI application we decide we need a widget that contains two buttons and that this widget is to appear within the main window of the application below the label as shown in the image below. class ButtonsFrame(tk.Frame) : def __init__(self, parent) : tk.Frame.__init__(self, parent.root) b1 = tk.Button(self, text= "A") b2 = tk.Button(self, text = "B") ## lines 1 and 2 ## class MainWindow(object) : def __init__(self, root) : self.root = root tk.Label(root, text="Buttons").pack() bf = ButtonsFrame(self) ## line 3 ## What is the required code for ## lines 1 and 2 ##? b1.pack(side=tk.LEFT, expand=1) b2.pack(side=tk.LEFT) b1.pack(side=tk.LEFT, expand=1) b2.pack(side=tk.LEFT, expand=1) b1.pack(side=tk.LEFT, fill=tk.BOTH) b2.pack(side=tk.LEFT, fill=tk.BOTH) b1.pack(side=tk.LEFT, ll=tk.BOTH) b2.pack(side=tk.LEFT, ll=tk.X) More than one of the other choices is correct. 1 points Save Answer QUESTION 33 What is the required code for ## line 3 ##? bf.pack(expand=1) bf.pack(ll=tk.BOTH, expand=1) bf.pack() bf.pack(ll=tk.BOTH) More than one of the other choices is correct. 1 points Save Answer QUESTION 34 To create a menu in a window, use ______ menubar = tk.Menu(master) menubar = tk.MenuBar(master) menubar = tk.Menu() menubar = tk.MenuBar() 1 points Save Answer QUESTION 35 Which of the following is true? Lists are mutable but dictionaries are immutable User dened classes are by default immutable Values and keys in dictionaries must both be immutable Strings, integers, oats, booleans and image objects are all immutable None of the other options are true 1 points Save Answer QUESTION 36 What will be returned after the following commands are entered? import operator print(sum(list(map(operator.mul, [1,2,3,4],[5,6,7,8])))) 70 [5, 12, 21, 32] 260 [50, , 60, 70, 80] None of the other options are correct 1 points Save Answer QUESTION 37 What is the value of g after the following is evaluated? y = ['a', 'b'] g= [2] y.extend([4]) g.append(y) [2, ['a', 'b', 4]] [2, 'a', 'b', [4]] None Error 1 points Save Answer QUESTION 38 What will be the value of x after evaluating these statements? x = [1, 2, 3, 4] x.append(x.pop(2)) x.insert(2, x.pop(1)) [1, 2, 3, 4] [2, 4, 3, 1] [1, 3, 2, 4] [1, 4, 2, 3] None of the other options are correct 1 points Save Answer QUESTION 39 The next two questions refer to the following function denition. def get_days(years) : total_days = 0 while years >= 0 : total_days += 365 years -= 1 return total_days When the following code is executed, what, if any, error will be thrown? years = input("How many years to convert to days? ") days = get_days(years) print("You entered ", years, "years.") print("That is {} days.".format(days)) ValueError NameError TypeError No error will be thrown 1 points Save Answer QUESTION 40 What will the following function call return? (If you determined that an error would be thrown in the previous question, assume that it has been xed.) get_days(2) 365 730 1095 None of the other choices are correct 1 points Save Answer QUESTION 41 What is the value of z after the following commands are entered? gf = ['Mo', 'Python'] z=[''.join([gf[i][j] for i in range(len(gf[0]))]) for j in range(len(gf))] [’MP’, ’oy’] [’My’, 'Po'] [’MyPo’] Error None of the other options are correct 1 points Save Answer
学霸联盟