Partial preview of the text
Download Intro to Programming (Python) Final Exam Multiple Choice Questions & Answers. and more Exams Introduction to Computers in PDF only on Docsity!
Name: Score: / Final Exam Part 1 Which of the following objects is immutable? © A. Dictionary © 8B. List © ©. Set © p. Tuple Answer Point Value: 1.0 points Answer Key: D Which of the following objects is mutable? © 1. Float © 8B. String © ©. Frozen Set © D. Boolean © E. None of the Above Answer Point Value: 1.0 points Answer Key: E In Python, everything is an object. © True © False Answer Point Value: 1.0 points Answer Key: True When creating the variable, b = 10, b contains the value 10. © True © False Answer Point Value: 1.0 points Answer Key: False An object whose internal data can be changed is called a object. Answer Point Value: 1.0 points Answer Key: mutable Fill in the command such that the type of variable x is printed. print(___) Answer Point Value: 1.0 points Answer Key: type(x) Which of the following is a valid python comment? op, Hf This is a comment. © B. $ This is a comment. Oc @ This is a comment. © D. # This is a comment. Answer Point Value: 1.0 points Answer Key: D The results of 6//7 is: The results of 6%7 is: The results of 6*7 is: The results of 6**7 is: Answer Point Value: 4.0 points Answer Key: 0, 6, 42, 279936 The result of True and True is: The result of True or False is: The result of 1 == 'l'is:_ The result of 1 ==1.0is: The result of 1 == True is: Answer Point Value: 5.0 points Answer Key: True, True, False, True, True Casting a string variable holding a string-encoded float value as an integer will result in an integer variable type. © True © False Answer Point Value: 1.0 points Answer Key: False What will be printed? Attachments x = 30 my if: x >= 38: print("Hello") elit % <= 30% print("Goodbye") else: print("IDK...") won ant wr . Goodbye © B. Hello IDK... © C.IDK.. . Hello Goodbye . Hello © F. Hello Goodbye IDK... Answer Point Value: 1.0 points Answer Key: E Attachments 1 def functioni(): 2 print("This is function 1") 3 4 def function2(): 5 print("This is function 2") 6 7 def function3(): 8 print("This is function 3") 9 1@ def function4(*func): 11 for x in func: 12 print("What function is this?") 13 x() 14 print("Now I know...") 15 return(lambda x: print(x)) 16 17 18 test = function4(function1, function2, function3) 19 28 test("What function is this?") Given the attached code, __ statements will be printed. The first statement printed will be: The fifth statement printed will be: The second last statement will be: NOTE: If you think an error occurs at any point in the code, please write error for the associated blanks. Answer Point Value: 4.0 points Answer Key: 10, What function is this?, This is function 2, Now | know... Given the variable: x = "myString" The command that creates an iterator from variable x is: Answer Point Value: 1.0 points Answer Key: iter(x) Given the attached code, the character m will be the result of the first print statement and the character y will be the result of the second print statement. Attachments 1 x = "myString" 2 print(next(iter(x))) 3 print(next(iter(x))) © True © False Answer Point Value: 1.0 points Answer Key: False Attachments 1 points = [10, 45, 2, 67, 82, 44, 23] 2 new_points = list(filter(lambda x: (x % 2 != @), points)) 3 print(new_points) The result of the attached code is: Answer Point Value: 1.0 points Answer Key: [45, 67, 23] In regular expressions, the * metacharacter denotes: © A. A set of characters © B. Ends with © ©. Starts with © p, Signals a special sequence Answer Point Value: 1.0 points Answer Key: C In regular expressions, [a-zA-z] returns a match for any character alphabetically between a and z, lower case or upper case. © True © False Answer Point Value: 1.0 points Answer Key: True The regular expression: "“Ta-zA-Z]{3}[0-9]+" will match the string ECE9013 but not 9013ECE9013 © True © False Answer Point Value: 1.0 points Answer Key: True "ECE9013: Intro to Programming for Engineers" split() and "ECE9013: Intro to Programming for Engineers".split(" ") will result in the same number of new strings created. © True © False Answer Point Value: 1.0 points Answer Key: True “ECE9013: Intro to Programming for Engineers".split(" ") results in __ strings created. "ECE9013: Intro to Programming for Engineers".split(":") results in__ strings created Answer Point Value: 2.0 points Answer Key: 6, 2 Attachments 1 x = “ECE9Q13: Intro to Programming for Engineers" 2 print(x[2:10:2]) The result of thee attached codeblock is Answer Point Value: 1.0 points Answer Key: E03 Which of the attached lines of code produce to an error? Attachments 1 x = "ECE9013: Intro to Programming for Engineers” 2 x[19] = 3 3 x[10] == 3 © A. Line l © B. Line 2 © Cc. Line 3 © D. None of the lines of code produce an error. Answer Point Value: 1.0 points Answer Key: B When running the attached code, how many times will the statement "Still running" be printed? Attachments te = -2 2 while x > @: 3 print("Still running") 4 x t= 1 © A. The statement will be printed one time. © B. The statement will not be printed. eC. The code results in an infinite loop; the statement will be printed an infinite number of times. © 1D. There is an error in the code; the statement will not be printed. Answer Point Value: 1.0 points Answer Key: B Attachments 1 x = ["Hello", "World"] 2 [y*2 for y in x] The following code results in a with elements, the first being and the last being Answer Point Value: 4.0 points Answer Key: list, 2, HelloHello, WorldWorld What is the output of the attached code? Attachments 1 c=@ 2 for i in “abe xyz": 3 c=c+1 4 print(c) + AO UO wD OD Answer Point Value: 1.0 points Answer Key: B Which of the following returns an empty set? oO a. set(range(3,3)) © 8B. set(range(1, -3, -5)) © ©. set(-2, 4, 3)) © D. All other options return empty sets. Answer Point Value: 1.0 points Answer Key: A Attachments 1 listi=[1,2,3,4,5] 2 s=0 3 i=1 4 while(i in list1): 5 s=sti 6 i=itl 7 print(s) The output of the attached code is : NOTE: If you believe the attached code produces an error, enter error for the blank. Answer Point Value: 1.0 points Answer Key: 15 How many times does the loop execute in the attached code? Attachments 1 i=0 2 while (i<10): 3 if(i%2): i=i+3 4 i=iti 5 print(i) © A.6 © BS Oca © p.3 Answer Point Value: 1.0 points Answer Key: C What is the output of the attachedcode? Attachments 1 def check_zero(func): 2 def wrap(num1, num2): 3 if num2 == @: 4 return "Undefined" 5 return func(num1, num2) 6 return wrap 7 8 def div(a, b): 9 return a/b 18 11 div = check_zero(div) 12 print(div(div(4, 2), div(@, 10))) © A. Undefined © B.2 © ¢.2,2 © Dd. 2,0 Answer Point Value: 1.0 points Answer Key: A What is the result of the attached code? Attachments def funci(func): def inner_func(*args, **kwargs): li = [pow(x, 2) for x in args] return func(1li, **kwargs) return inner_func @funcl def func2(1li): return li oan onuwnbwn a a NF ® @funcl def func3(1li): return [pow(x, @.5) for x in li] FPR R RR an anu & ww def func4(): print(func2(1, 2, 3, 4), func3(1, 2), func2(1, 2), func3(1, 2, 3, 4)) NNR FO wo 22 func4() op. [1, 4, 9, 16] [1.0, 2.0] [1, 4] [1.0, 2.0, 3.0, 4.0] © 8B. [1.0, 2.0, 3.0, 4.0] [1, 4, 9, 16] [1.0, 2.0] [1, 4] © Cc. [1, 4] [1, 4, 9, 16] [1.0, 2.0] [1.0, 2.0, 3.0, 4.0] © p. [1.0, 2.0] [1, 4] [1, 4, 9, 16][1.0, 2.0, 3.0, 4.0] Answer Point Value: 1.0 points Answer Key: A