Python_Practice5_ReviewSession-1

docx

School

Columbia University *

*We aren’t endorsed by this school

Course

5210

Subject

Computer Science

Date

Apr 3, 2024

Type

docx

Pages

8

Uploaded by DeaconHare3679

Report
Name: UNI: Python for Data Analysis Midterm Exam Practice Session 5 Review 1. What will be the output of the code below? (5 pts) d = {'Paul': 'e750144'} d['Julie'] = 'c677888' d['Lynn'] = 't899717' d['Julie'] = 'd999999' del d['Paul'] print(d) a. {'Paul': 'e750144', 'Julie': 'd999999', 'Lynn': 't899717' } b. {'Paul': 'e750144', 'Julie': ‘c677888’ , ' 'Lynn': 't899717 '} c. {'Paul': 'e750144', 'Lynn': 't899717'} d. {'Julie': 'd999999', 'Lynn': 't899717'} e. None of the above 2. What will be the output of the code below? (3 pts) Set1 = set([11, 13, 15, 17, 11]) Set1.add(78) Set1.discard(13) Set1.add(99) Set1.remove(15) print(Set1) a. {99, 11, 78, 17} b. (11, 15, 17, 11, 99) c. {11, 17, 11, 99, 78} d. None of the above 3. To add a new element to a list we use which function? (3 pts) a. lst1.add(7) b. lst1.append(7) c. lst1.addLast(7) d. lst1.addEnd(7)
4. What will be the output of the code below? (3 pts) cities = ['New York', 7.04, 'Miami', 'San Francisco', '', 31] cities.reverse() print(cities[-3:-1]) a. [7.04, 'New York'] b. ['Miami', 7.04] c. ['New York', 7.04, 'Miami'] d. ['Miami', 7.04, 'New York'] e. None of the above 5. Which of the statements correctly describes what happens when the following statements are run? (5 pts) myLst = (7, 9) myLst.append(11) myLst.append('hello') print(myLst) a. An error will be thrown by the "append()" statement on line 3 b. An error will be thrown by the "append()" statement on line 2 c. The program will print out “[7, 9, 11, ‘hello’]” d. None of the above 6. In a print statement, you can set the ______ argument to an empty string to stop the output from advancing to a new line (3 pts) a. stop b. sep c. end d. newline e. None of the above 7. What would be the output of the following statements? (3 pts) str1 = 'Edward is a dedicated Employee' print(str1.lower().strip('e')) a. Edward is a dedicated Employe b. dward is a dedicated employ c. dward is a dedicated Employ d. edward is a dedicated employee e. None of the above
8. What will be the output of the code below? (5 pts) myDict = {'NY': 'New York', 'NJ': 'New Jersey', 'DE': 'Delaware', 'VA': 'Virginia', 'CA': 'California', 'FL': 'Florida'} state = myDict.pop('DE', 'Not Found') state2 = myDict.pop('PA', 'Not Found') k, v = myDict.popitem() del myDict['VA'] print(len(myDict)) a. 5 b. 4 c. 3 d. 2 e. Not Found 9. What is the output of the code below? (3 pts) lst1 = [7, ‘a’, 9] print(lst1 * 3) a. (7, ‘a’, 9, 7, ‘a’, 9, 7, ‘a’, 9) b. [7, ‘a’, 9, 7, ‘a’, 9, 7, ‘a’, 9] c. [21, ‘3a’, 27] d. None of the above 10. What is the output of the code below? (3 pts) myStr = ‘Python is a very powerful programming language’ x = myStr.split() print(x[-4:-1]) a. (‘Python’, 'is', 'a', 'very') b. [‘a’, 'very', 'powerful', 'programming', 'language'] c. [ 'very', 'powerful', 'programming'] d. None of the above 11. What is the output of the code below? (3 pts) x = 7*1**3 print(x) a. 7 b. 21
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
c. 343 d. None of the above 12. What is the output of the code below? (5 pts) Set1 = set('street') Set2 = set([37, 49, 55]) Set3 = set(['street', 'city']) Set4 = Set1.union(Set2).union(Set3) print(Set4) a. {'e', 'r', 49, 37, 55, 't', 's', 'city', 'street'} b. ['e', 'r', 49, 37, 55, 't', 's', 'city', 'street'] c. {'street', 'city', 37, 49, 55} d. {‘street’} e. None of the above 13. What is the output of the code below? (3 pts) x = 1 def calc_1(): x = 2 y = 3 return x calc_1() print (calc_1(), x) a. 1 b. 2 c. 1 2 d. 2 1 e. None of the above 14. What is the output for the code below? (3 pts) def gen_num():   for i in range(1, 36, 5):   print (i, end=’ ‘) gen_num()  a. 1 6 11 16 21 26 31 36 b. (1,  6, 11, 16, 21, 26, 31) c. 1 6 11 16 21 26 31 d. {1, 6, 11, 16, 21, 26, 31, 36} d. None of the above
15 . Which of the following code will result in an error? (5 pts) I. data_1 = ['a', 'b', 'c', 'd', 'e'] data_1[1] = 'f' II. data_2 = ('a', 'b', 'c', 'd', 'e') data_2[1] = 'f' III. data_3 = {1:'a', 2:'b', 3:'c', 4:'d', 5:'e'} data_3[1] = 'f' IV. data_4 = 'abcde' data_4[1] = 'f' a. I, III, IV b. IV c. II, IV d. None of the above 16 . What will be the elements contained in "salad1" after the following operations? (3 pts) set1 = set(['strawberries', 'blueberries', 'pineapple', ‘banana’]) set2 = set(['strawberries', ‘banana’]) set3 = set(['banana', 'orange', 'melon']) salad1 = set1.intersection(set2).difference(set3) print(salad1) a. {‘blueberries’, 'pineapple'} b. { } c. {'strawberries', 'banana'} d. {'strawberries'} e. None of the above 17 . What is the output of the code below? (3 pts) lst1 = ([-11, ‘a’, 88], ‘Susan’, (7,9,1)) print(lst1[0][1], end=' ') print(lst1[2][0]) a. Index Error b. -11 7 c. (S, 88)
d. a 7 e. None of the above 18. What is the output of the code below? (3 pts) Ids={'A':'UNI650178','P':'UNI750777','M':'UNI778133',‘N’:‘UNI787878’} print(Ids['N']) a. KeyError b. UNI650178 c. UNI787878 d. None of the above 19. What will the code below print? (3 pts) data1=[] for j in range(3): row = ['C'] * 3 data1.append (row) data1[0][2] = '*' print(data1) a. [['*', 'C', 'C'], ['C', 'C', 'C'], ['C', 'C', 'C']] b. [['C', 'C', '*'], ['C', 'C', 'C'], ['C', 'C', 'C']] c. [['C', 'C', 'C'], ['C', 'C', 'C'], ['*', 'C', 'C']] d. None of the above 20. What is the output of the code below? (3 pts) myStr = ‘Python for Data Analysis’ x = myStr.split() print(x[-3:-1]) a. (‘for’, ‘Data’) b. [‘for’, ‘Data’, ‘Analysis’] c. [‘for’, ‘Data’] d. None of the above 21. Suppose you have a datetime string str1 = ‘06/25/2019 12:30:08 PM’ . How would you slice this string in order to get just the time? (3 pts) a. str1[0:10:2] b. str1[-11:] c. str1[11:19]
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
d. str1[-7:] e. None of the above 22. What is the output of the code below ? (3 pts) t1 = ([2, 3, 5], [6, 10, 11], [9, 8, 7]) t1[1][1] = 13 print(t1[1]) a. 13 b. Type Error: tuple object does not support item assignment c. [6, 13, 11] d. none of the above 23. What will the following statement output ? (3 pts) values = [['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D']] values.append([1, 2, 3, 4]) i = len(values)-1 values[i].insert(1, 'z') print(values[2][2]) a. z b. 1 c. 2 d. A e. B 24. Which statement is not true? (3 pts) a. Lists are mutable in Python. A list can have elements modified in Python. b. Tuples are immutable in Python. c. Python supports appending data to a file. d. Strings in Python are immutable. e. Python is not a case sensitive language. 25. What is the output of the code below? (3 pts) def my_func(l): x = [] y = [7, 8, 9] for i in l: if i in y: x.append(i) return x print(my_func([1,2,2,3,3,3,3,4,4,5,7,9])) a. [1, 2, 3, 4, 5, 7, 9]
b. [7, 9] c. {7} d. [7, 8, 9] e. None of the above Solution: 1. D 2. A 3. B 4. B 5. B 6. C 7. B 8. C 9. B 10.C 11.A 12.A 13.D 14.C 15.C 16.D 17.D 18.C 19.B 20.C 21.B 22.C 23.C 24.E 25.B