COMP204_S2020_final

.pdf

School

McGill University *

*We aren’t endorsed by this school

Course

204

Subject

Computer Science

Date

Jan 9, 2024

Type

pdf

Pages

18

Uploaded by mayarogerss

December 2019 Supplemental Examination Intro to Computer Programming for Life Sciences COMP-204 March, 2020 EXAMINER: Mathieu Blanchette ASSOC. EXAMINER: Yue Li STUDENT NAME: McGILL ID: INSTRUCTIONS CLOSED BOOK X OPEN BOOK SINGLE-SIDED PRINTED ON BOTH SIDES OF THE PAGE X MULTIPLE CHOICE Note: The Examination Security Monitor Program detects pairs of students with unusually similar answer patterns on multiple-choice exams. Data generated by this program can be used as admissible evidence, either to initiate or corroborate an investigation or a charge of cheating under Section 16 of the Code of Student Conduct and Disciplinary Procedures. ANSWER BOOKLET REQUIRED: YES NO X EXTRA BOOKLETS PERMITTED: YES NO X ANSWER ON EXAM: YES X NO EXAM: SHOULD THE EXAM BE: RETURNED X KEPT BY STUDENT PERMITTED X Specifications: Two double-side pages, 8.5 inches x 11 inches NOT PERMITTED CRIB SHEETS: DICTIONARIES: TRANSLATION ONLY REGULAR X NONE CALCULATORS: NOT PERMITTED X PERMITTED ( Non-Programmable ) ANY SPECIAL INSTRUCTIONS: Answer all questions on this exam. This exam contains 22 questions on 18 pages. If you need extra space, use the empty pages at the end of the exam. Course: COMP-204 Intro to Computer Programming for Life Sciences Page number: 1 / 18
Multiple choice questions (21 points). Consider the following code 1 c l a s s A() : 2 def __init__( s e l f , B) : 3 s e l f .C = B 4 5 def D( s e l f ) : 6 s e l f .C = 1 7 8 def E() : 9 F = A() 1. (2 points) Which of A, B, C, D, E, or F is a method? Select ALL correct answers. A B C D E F 2. (2 points) Which of A, B, C, D, E, or F is an attribute? Select ALL correct answers. A B C D E F 3. (2 points) Which of A, B, C, D, E, or F is an object? Select ALL correct answers. A B C D E F 4. (3 points) Which line(s) of this program will trigger an error when it is executed. Select ALL correct answers. 1 d = { "Mathieu" : " Blanchette " , "Yue" : " Li " , 15:[1 ,3 ,5 ,15]} 2 d [ "Yue" ]= " L a n n i s t e r " 3 d [ "Mathieu" ][3]= "X" 4 d [ 1 5 ] = 10 5 d [ ( 3 , 8 ) ] += 1 A. Line 1 B. Line 2 C. Line 3 D. Line 4 E. Line 5 Course: COMP-204 Intro to Computer Programming for Life Sciences Page 2 Page number: 2 / 18
5. (3 points) Assume s = "AGAGTC". Which of the following boolean expression(s) will evaluate to True? Select ALL correct choices. A. s[4] == "T" B. s[-2:-1][0] == "T" C. len([ x for x in s if x=="T"]) == 1 D. not ( len(s)==6 or s == set(s) ) E. s[0]<s[1] and s[1]<s[2] 6. (3 points) What would be the sensitivity and specificity of the following prostate cancer prediction decision tree on the test data given below? Select ONE correct answers. Age PSA Gender Status 76 1.87 Male Cancer 56 1.74 Female Normal 59 1.72 Male Normal 76 1.82 Male Cancer 75 1.97 Male Normal 73 1.45 Female Normal 67 1.63 Male Cancer A. Sensitivity = 75%, Specificity = 66.67% B. Sensitivity = 66.67%, Specificity = 75% C. Sensitivity = 25%, Specificity = 33.33% D. Sensitivity = 33.33%, Specificity = 25% E. Sensitivity = 66.67%, Specificity = 25% Course: COMP-204 Intro to Computer Programming for Life Sciences Page 3 Page number: 3 / 18
7. (3 points) The functions below are supposed to determine whether a list of strings contains dupli- cates (i.e. at least two elements that are equal). Which ones work correctly? Select ALL correct functions. 1 def contains_duplicates_A (L) : 2 r e t u r n le n ( s e t (L) )>0 3 4 def contains_duplicates_B (L) : 5 s = {x f o r x in L} 6 r e t u r n le n ( s ) < l en (L) 7 8 def contains_duplicates_C (L) : 9 d = {} 10 f o r index , x in enumerate (L) : 11 d [ index ] = x 12 i f l en (d . keys () )!= l en (L) : 13 r e t u r n True 14 r e t u r n False 15 16 def contains_duplicates_D (L) : 17 f o r index , x in enumerate (L) : 18 i f x in L [ index +1: l en (L) ] : 19 r e t u r n True 20 r e t u r n False 21 22 def contains_duplicates_E (L) : 23 f o r index , x in enumerate (L) : 24 i f x not in L [ index +1: l e n (L) ] : 25 r e t u r n False 26 r e t u r n True A. contains_duplicates_A B. contains_duplicates_B C. contains_duplicates_C D. contains_duplicates_D E. contains_duplicates_E Course: COMP-204 Intro to Computer Programming for Life Sciences Page 4 Page number: 4 / 18
Short answer questions (35 points) 8. (2 points) What will be printed when this program is executed? 1 L = [5 , (3 ,6) , " Hello " , 4] 2 output = [ ] 3 f o r i in range (2) : 4 x = L . pop (0) 5 y = L . pop (0) 6 output . extend ( [ x , x ] ) 7 p r i n t ( output ) 9. (2 points) What will be printed when this program is executed? 1 def f u n c t i o n ( x , y ) : 2 f o r i in range ( y ) : 3 x += y 4 r e t u r n x 5 6 x = 2 7 y = 3 8 z = f u n c t i o n ( x , y ) 9 p r i n t ( x , y , z ) 10. (2 points) What will be printed when this program is executed? 1 def f u n c t i o n ( x , y ) : 2 f o r i in y : 3 x . extend ( y ) 4 r e t u r n x 5 6 x = [ 2 ] 7 y = [ 3 , 4 ] 8 z = f u n c t i o n ( x , y ) 9 p r i n t ( x , y , z ) Course: COMP-204 Intro to Computer Programming for Life Sciences Page 5 Page number: 5 / 18
11. (3 points) What will be printed when this program is executed? 1 import math 2 def fun1 ( x ) : 3 i f x <0: 4 r a i s e ValueError 5 r e t u r n math . s q r t ( x ) 6 7 def fun2 () : 8 fun1 ( - 2) 9 r e t u r n fun1 (1) 10 11 a = b = c = 0 12 t r y : 13 a = fun1 (4) 14 b = fun2 () 15 c = fun1 (9) 16 except ValueError : 17 p r i n t ( "Problem" ) 18 p r i n t (a , b , c ) 12. (3 points) What gets printed when this program is executed? 1 L = [1 , 6 , 8 , 2 , 8] 2 p r i n t ( [ x f o r x in L i f x >5] ) 3 p r i n t ( {x f o r x in L i f x>5} ) 4 p r i n t ( [ i f o r i , x in enumerate (L) i f x >5] ) 13. (3 points) Write the function dot_product that takes as arguments two lists of integers of the same lengths, and returns the sum of the products of each corresponding elements. For example, dot_product([3, 1, 2], [4, 1, 3]) should return 19, because 3*4+1*1+2*3 = 19. Make your function as short as possible. Course: COMP-204 Intro to Computer Programming for Life Sciences Page 6 Page number: 6 / 18
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