COMP1126_further_Practice_Qs.pdf.pdf

Full Transcript

OurVLE Home ► My courses ► Online Examinations ► Semester 1, 2020/2021 Exam Containers ► Undergraduate Exam Only Containers | S1, 2020/21 ► EXAM_COMP1126 | S1_2020/21 ► Examination Area ► Final Exam - COMP1126 EXAMINATION ONLY - INTRODUCTION TO COMPUTING I Started on Monday, 7 D...

OurVLE Home ► My courses ► Online Examinations ► Semester 1, 2020/2021 Exam Containers ► Undergraduate Exam Only Containers | S1, 2020/21 ► EXAM_COMP1126 | S1_2020/21 ► Examination Area ► Final Exam - COMP1126 EXAMINATION ONLY - INTRODUCTION TO COMPUTING I Started on Monday, 7 December 2020, 12:04 PM State Finished Completed on Monday, 7 December 2020, 2:04 PM Time taken 2 hours QUESTION 1 If the following expression were entered in the python interpreter what would be the Complete output? Marked out of 1.00 >>> 61 > 51 or 17 > 41 Flag question Select one: a. True b. Boolean c. False d. 61 e. 41 QUESTION 2 Given the following code: Complete def tester(p,t): Marked out of 1.00 while p >= 0: p -= 1 Flag t = p+1 question return t*2 What would be the result of evaluating the following? >>> tester(5,2) Select one: a. Infinite loop b. 8 c. 0 / d. 4 e. 6 QUESTION 3 Select the following that would complete the code snippet [CODE], such that the Complete function returns the smallest of 3 given numbers. Marked out of 1.00 def smaller(x,y): if x < y: Flag return x question else: return y def smaller_of_three(x,y,z): if smaller(x,y) < z: return CODE else: return z Select one: a. smaller(x,y) b. x c. y d. z e. x < y QUESTION 4 Complete the following recursive function that counts clouds with widths that are more Complete than 5K wide. The list clouds = [(l,w),(l,w)] contains tuples where the first element is the length and the second is the width of a cloud. Marked out of 1.00 def counting_clouds(clouds): Flag if clouds == []: question return 0 elif clouds > 5: #CODE_BLOCK else: return counting_clouds(clouds[1:]) Select one: a. return 1 + counting_clouds(clouds[1:]) b. / return counting_clouds(clouds[1:]) c. return 1 + counting_clouds(clouds[:1]) d. return 1 + counting_clouds(clouds[:]) e. return 1 + counting_clouds(clouds) QUESTION 5 In the code discussed in class for fibonacci series, which version took the longest time to Complete run? Marked out of 1.00 Select one: Flag a. while loops question b. tail recursion c. augmenting recursion d. all loops QUESTION 6 What will this function return if the following statement is evaluated? Complete >>> stopTime(100) Marked out of 1.00 Flag question / def stopTime(Time): endOftime = 999 if(Time == endOftime-1): return -1 else: return 0 time = 0 running = 0 while time == running: time +=1 time = stopTime(time) running += 1 Select one: a. 0 b. Infinite Loop c. Error d. -1 e. 998 QUESTION 7 What will this function return if lst = [1,2,3,4,5] Complete def ForFunction3(lst): Marked out of 1.00 for el in lst: if(el == 0): Flag lst = lst + [el] question return len(lst) Select one: a. Infinite Loop b. 5 c. 10 d. [1,2,3,4,5,1,2,3,4,5] e. [1,2,3,4,5] QUESTION 8 What will be the result of evaluating Complete >>> pass_grade(50) Marked out of 1.00 def pass_grade(w): / return w = 50 Flag question Select one: a. 50 b. Error c. True d. False QUESTION 9 Consider the following function digits Complete [Note: // operator returns the quotient of a division operation i.e. 15//4 returns 3] Marked out of 2.00 def digits(number): Flag def count(number,total): question if number>> mylst=["COMP1126",[0,1,2,3,4,5,6,7], [], [[1,2,3]] ] Marked out of 4.00 Match the output with the given list statements. Flag question mylst[:4] 'COMP' mylst 1 / mylst[-1] [1,2,3] mylst[2:-1:2] [2,4,6] QUESTION 11 Which of the following statements will correctly complete the function getTime(X,Y) Complete which returns the time it takes to go from one location to the next given the Map list.If no path is found the function returns -999. Marked out of 3.00 The list (Map) is a set of locations with the length of time it takes to go between two Flag points in either direction. question Examples: >>> getTime("Gym","School") >>> 4 >>> getTime("School","Gym") >>> 4 Map = [("Gym","School",4),("Gym","Office",2),("School","Office",5),("Home","Sch ool",10),("School","Home",3),("Home","Gym",4), ("Office","Home",11)] def getTime(X,Y): for path in Map: if CODE_A == X and CODE_A == Y: return CODE_C elif path == Y CODE_B path== X: return CODE_C return -999 Which of the following statements will correctly complete the function? In place of Code_A : path[X] path[Y] path path Map Map Map path In place of Code_B : or != else and In place of Code_C : Map / path path Map QUESTION 12 Given the following function: Complete def whatif(a,b,c): Marked out of 1.00 if (a = c) or (a = b) : return a Flag elif (b = c) or (b = a) : question return b else: return c What would be the result of evaluating the following? >>> whatif(5,6,7) Select one: a. 6 b. Error c. 7 d. 5 e. Infinite Loop QUESTION 13 Select an appropriate base case for the following recursive function. Complete def get_even(lst): Marked out of 1.00 if #CODE: return [] Flag elif lst% 2 == 0: question return [lst] + get_even(lst[1:]) else: return get_even(lst[1:]) Select one: a. lst b. lst [2:] c. lst = [ ] d. lst == e. lst == [ ] / QUESTION 14 If the following were entered in the python interpreter in the sequence shown what would Complete be the output? Marked out of 1.00 >>> Z = 30 Flag question >>> Z == 10-60 >>> Z = 20 +15 >>> Z == 30 Select one: a. True b. 50 c. 35 d. False e. 30 QUESTION 15 Which of the following are primitive python data types: Complete Select one or more: Marked out of 1.00 a. letter Flag b. decimal question c. boolean d. integer QUESTION 16 Which of the following statements will correctly complete the function powerx(x,y) Complete which returns x raised to power of y Marked out of 3.00 def powerx(x,y): result = 1 Flag while CODE_A >= 1 : question result = CODE_B y = y - 1 return CODE_C Which of the following statements will correctly complete the function? In place of Code_A : x / result y y+1 In place of Code_B : x*x result - x result * x result + x In place of Code_C : y x result x*y QUESTION 17 Consider the following Python function Complete The function f is intended to be used to calculate the factorial of a positive integer. For Marked out of 2.00 example, the factorial of 5 is calculated as: 5 x 4 x 3 x 2 x 1=120 Flag def f(n): question if n==0: CODE_A else: return CODE_B Which of the following statements will correctly complete the function? For CODE_A: 1 return 1 0 return 0 For CODE_B: n * f(n - 2) n * f(n - 1) n + f(n - 1) n * f(n + 1) / QUESTION 18 Write functions that perform subtraction recursively. You have been given two functions Complete pred and succ, pred given a number returns the previous number and succ given a number returns the next number. Marked out of 2.00 def succ(x): Flag return x+1 question def pred(x): return x-1 >>> pred(5) 4 >>> succ(5) 6 Logic for subtraction is that given two numbers as arguments keep on getting the predecessor (pred) of the first and the predecessor (pred)of the second, until the second argument is 0 then the first argument is the answer. >>> subtraction(5,3) 2 def subtraction(x,y): if y == 0: return CODE_A else: return CODE_B Which of the following statements will correctly complete the function subtraction above? In place of Code_A : 1 y x 0 In place of Code_B : subtraction(pred(y), pred(x)) subtraction(x, y) subtraction(pred(x), pred(y)) subtraction(pred(y), x) / QUESTION 19 If the following were entered in the python interpreter in the sequence shown what would Complete be the output? Marked out of 1.00 >>> A = 16 Flag question >>> B = 24 >>> B == A and 34 < 35 Select one: a. 16 b. 0 c. True d. False e. 24 QUESTION 20 How many times will this code snippet enter the while loop? Complete >>> n = 10 Marked out of 1.00 >>> s = 7 >>> b = 5 Flag question >>> while n > s and s >= b: b = b+1 Select one: a. 3 b. 5 c. 7 d. 10 e. 4 QUESTION 21 What would the following function print? Complete >>> adj = ["red", "big"] Marked out of 1.00 >>> fruits = ["banana", "apple"] Flag question / def nested(): for x in adj: for y in fruits: print(x, y) Select one: a. big apple red apple red banana big banana b. big apple big apple red banana red banana c. red banana big banana red apple big apple d. red banana red apple big banana big apple e. big apple red apple big banana red banana QUESTION 22 How many times will be the word "exam” be printed by the following code fragment? / Complete >>> for x in range(20,9,-1): Marked out of 1.00 print ("exam”) Flag question Select one: a. 10 b. 11 c. 9 d. Infinite Loop e. 12 QUESTION 23 Match the following inputs to their data types Complete Marked out of 1.00 ["hello", "again"] list Flag (2,3) tuple question "hello" string QUESTION 24 What will the following recursive function return if lst = [1,2,3]? Complete def function(lst): Marked out of 1.00 a = 0 if lst == []: Flag return 1 question else: a+=1 return a * function(lst[1:]) * math.sqrt(16) Select one: a. 64.0 b. 32.0 c. 1 d. 4.0 e. 0.0 QUESTION 25 Consider the following Python functions: Complete Marked out of 2.00 / Flag def whatisthis(x): question return foo1()+2 def foo1(): def foo2(x): return 1 + x return foo2(2) What would be the output of the following function calls below? >>>whatisthis(2) + foo2(2) 4 5 Error 1 >>>foo2(3) 4 3 Error 2 QUESTION 26 Consider the following Python functions: Complete def f1(x): Marked out of 2.00 if x == 0: return True Flag else: question return f2(x-1) def f2(x): if x == 0: return False else: return f1(x-1) What is the expected output from Python for the following expression? >>>f1(5) True False Error 0 / What would be more meaningful names for functions f1and f2 above (respectively)? isTrue and isFalse is_a_Function1 and is_a_Function2 is_HCF and is_LCM is_Even and is_Odd QUESTION 27 Which of the following statements will correctly complete the function isprime(x) which Complete returns True if x is a prime number and False otherwise. [Note: a number is considered to be prime if is divisible by 1 and itself only]. Marked out of 3.00 Flag def isprime(x): question c = CODE_A while c < x: if x%c == 0: return CODE_B c=c+1 return CODE_C Which of the following statements will correctly complete the function? In place of Code_A : 0 1 2 c+1 In place of Code_B : x c False True In place of Code_C : x c True False / QUESTION 28 Given the following function: Complete def thisFunction(X): Marked out of 1.00 lst = ['2',3,4,'6',8,11,'95'] return lst[X] Flag question What would be the result of evaluation the following: >>> thisFunction(int(thisFunction(3))) Select one: a. ['2',3,4,'6',8,11,'95'] b. 95 c. Error d. 11 e. '95' QUESTION 29 def square(x): Complete print(x*x) Marked out of 1.00 Given the function square, what would be the output of the following statement. Flag >>> square(3)+5 question Select one: a. TypeError b. 14 c. 9 QUESTION 30 Select the following that would complete the code snippet to print Even values from 0 to Complete 10? The code should print -> 2,4,6,8,10 Marked out of 1.00 for i in CODE: if i%2 == 0: Flag print(i) question Which of the following statements will correctly complete the code snippet? In place of CODE : range(1,10) / range(1,11) [1,10] (0,11) QUESTION 31 Evaluate >>> come(2) Complete def come(a): Marked out of 1.00 return forth(a) Flag question def forth(x): return jedi(x)+2 def jedi(x): return knights(3)+x def knights(x): return 5+x Select one: a. 10 b. 7 c. 12 d. 27 QUESTION 32 Consider the following Python functions: Complete def calc(y): Marked out of 2.00 def helper(x,y): return x+y Flag if(y%2 != 0): question return y else: return CODE_BLOCK What would the function calc return if the CODE_BLOCK was replaced with helper(x,x) and y = -172. >>> calc(-172) 344 Error / -172 0 What would the function calc return if the CODE_BLOCK was replaced with helper(y,y) and y = 250. >>> calc(250) 250 500 Error x QUESTION 33 Function oddList(lst) returns the odd elements in the given list passed as an Complete argument. Marked out of 3.00 >>>oddList([1,2,3,5,4,6,7]) [1,3,5,7] Flag question def oddList(lst): if lst == []: return CODE_A elif lst % 2 == 0: return CODE_B else: return CODE_C Which of the following statements will correctly complete the function? In place of Code_A : lst 0 [] lst % 2 In place of Code_B : oddList(lst[1:]) oddList[lst[1:]] oddList(lst[:1]) oddList(lst]) In place of Code_C : lst + oddList(lst[1:]) / [lst] + oddList(lst[1:]) [lst] + oddList[lst[1:]] lst + oddList(lst) Finish review

Use Quizgecko on...
Browser
Browser