Practice3_Spring_2024-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
Python for Data Analysis – Practice 3 1. Which of the following is invalid? (D) a. _x = 7 b. __x = 77.1 c. __x__ = 78 d. 1st_x = 1 e. None of the above 2. Which of the following cannot be a variable? (B) a. __init__ b. in c. it d. on e. None of the above 3. What will the code below print? (D) str1 = 'asdfgh' k = 'a' while k in str1: str1 = str1[:-1] print(k, end = ' ') a. (a, s, d, f, g, h) b. a s d f g h c. ‘asdfgh’ d. a a a a a a e. None of the above 4. What is the output of the following? (B) print ( 'xy,78'. isalnum ()) a. True b. False c. 0 d. None of the above
5. What will be the output? my_party = [ 'cake', 'balloons', 'gift', 'drinks' ] my_party. insert (my_party. index ( 'balloons' ), 'confetti' ) print (my_party ) a. [‘cake’, ‘balloons’, ‘gift’, ‘drinks’] b. [‘cake’, ‘confetti’, ‘balloons’, ‘gift’, ‘drinks’] c. [‘cake’, ‘confetti’, ‘gift’, ‘drinks’] d. None of the above 6. What is the output of the following? print ( 'Good*Morning!'. istitle ()) a. Good*Morning! b. False c. True d. None of the above 7. What is the output of the code below? print(‘asdfgh’.replace(‘sg’, ‘77’)) a. asdfgh b. a7df7h c. asd77h d. 77dfgh e. None of the above 8. What will be the output of the code below? for s in ''.join(reversed(list('water'))): print (s, end = ' ') a. w a t e r b. e t a w r c. r e t a w d. None of the above
9. What is the output of the code below? myStr = ‘I love Paris in the Spring’ a = myStr.split() print(a[-3:]) a. (‘in’, ‘the’) b. [‘the’, ‘Spring’] c. [‘in’, ‘the’, ‘Spring’] d. None of the above 10. What is the output of the code below? myDealer = {‘Color’:‘Blue’, ‘Make’:‘Toyota’, ‘Model’:’Rav4’, ‘Year’:2017} x = myDealer.pop(‘Color’, ‘Item not found’) myDealer.pop(‘Year’, ‘item not found’) print(x, end = ‘ ‘) print(len(myDealer)) a. Item not found b. Blue 2 c. Model 3 d. None of the abov e 11.What do we get when the code below is executed? grades = {‘Anna’: 9.1, ‘Lin’: 8.4, ‘John’: 9.3, ‘Sue’: 9.8} grades[‘Tim’] = 9.9 print(grades) a. {‘Anna’ : 9.1, ‘Lin’: 8.4, ‘John’: 9.3, ‘Sue’: 9.8} b. {‘Anna’ : 9.1, ‘Lin’: 8.4, ‘John’: 9.3, ‘Sue’: 9.8, ‘Tim’: 9.9} c. Index Error d. None of the above 12. Which is the output of the code below? str1 = “COLUMBIA UNIVERSITY” str1[-12:-3:2] a. UIEST b. AUIES c. Index Error d. None of the above
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
13.What is the output of the code below? def my_func(l): x = [] for i in l: if i not in x: x.append(i) return x print(my_func([1,2,2,3,3,3,3,4,4,5])) a. [1, 2, 2, 3, 3, 3, 3] b. [1, 2, 3. 4] c. [1, 2, 3, 4, 5] d. None of the above 14. What is the output of the code below? t1 = ('a', 's', 'd', 'f', 'g') s1 = ''. join( t1) print(s1) a. [ ‘a’, ‘s’, ‘d’, ‘f’, ‘g’] b. [‘asdfg’] c. Index Error d. asdfg e. None of the above 15. What is the output of the program below? t1 = (‘1’, 4.0, ‘b’, ‘U45’) t2 = list(t1) t2.remove(‘U45’) print(t2) a. (‘1’, 4.0. ‘b’) b. [‘1’, 4.0, ‘b’, ‘U45’] c. [‘1’, 4.0, ‘b’] d. Index Error e. None of the above
16. What is the output of the code below ? C1 = set() C1. add(‘Red’) C1. update([‘Blue’, ‘Green’]) print( C1) a. (‘Red’, ‘Blue’, ‘Green’) b. [‘Red’, ‘Blue’, ‘Green] c. (‘Blue’, ‘Green’) d. None of the above 17. What is the output of the code below? S1 = set([1, 7, 8, 3]) S2 = set([15, 31, 3]) S3 = S1 & S2 print( S3) S4 = S1 – S3 print( S4) a. { 3 } { 8, 1, 7 } b. ( 15, 31) ( 1, 7, 8) c. { 8, 3 } { 3 } d. None of the above 18.What is this code output? def fn_x():   for j in range(3, 15, 3):   print (j, end=’ ‘) fn_x()  a. 3 6 9 12 b. 3, 6, 9, 12 c. 3 6 9 12 15 d. None of the above
19.Which of the following data types is not supported in Python? a. List b. String c. Tuple d. Slice e. None of the above 20.Which method would you use to get all the elements in a dictionary returned as a list of tuples a. list b. pop c. items d. keys e. None of the above 21.When reading a file and calling the readline() method, the lstrip(‘\n’) function can be used to remove the next line character: a. True b. False 22. Given that the customer file references a file object, and the file was opened using the 'w' mode specifier, how would you write the string 'Jennifer' to the file? a. customer file.write('Jennifer') b. customer.write('w', 'Jennifer') c. customer.write('Jennifer') d. customer.input('Jennifer') 23. What is the output of the code below? PartySupplies = ['hats', ‘cake’, 'drinks', 'gift', 'candle', ‘plates’] PartySupplies.reverse() print(PartySupplies[-2:-1]) a. [‘cake’, ‘hats’] b. [‘candle’, ‘plates’] c. [‘gift’, ‘candle’] d. [‘cake’] e. None of the above
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
24. What is the output of the program below? G1 = set(['electric', 'cable', 'rent']) G2 = set(['electric', 'cable', 'transportation']) G3= set(['cable', 'clothing', 'entertainment']) G4= G1.intersection(G2).difference(G3) print(G4) a. {‘electric’} b. {‘electric’, ‘cable’} c. {‘clothing’, ‘entertainment’} d. None of the above 25.Suppose you have a datetime string str1 = ‘01/31/2019 10:30AM’ . How would you slice this string in order to get just the time? a. str1[11:16] b. str1[13:18] c. str1[14:] d. str1[-7:] e. None of the above
ANSWERS 1. d 2. b 3. d 4. b 5. b 6. c 7. a 8 . c 9. c 10. b 11. b 12. b 13. c 14. d 15. c 16. d 17. a 18. a 19. d 20 . c 21. b 22. c 23. d 24. a 25. d