CS177 Spring Midterm 2. April 02, 8pm-9pm. There are 25 multiple choice questions. Each one is worth 4 points.

Similar documents
CS177 Spring Final exam. Fri 05/08 7:00p - 9:00p. There are 40 multiple choice questions. Each one is worth 2.5 points.

CS177 Fall Midterm 1. Wed 10/07 6:30p - 7:30p. There are 25 multiple choice questions. Each one is worth 4 points.

CS 177 Fall 2014 Midterm 1 exam - October 9th

MA Exam 1 Fall 2015 VERSION 01

MA EXAM 3 INSTRUCTIONS VERSION 01 April 17, Section # and recitation time

MA EXAM 3 INSTRUCTIONS VERSION 01 April 14, Section # and recitation time

MA EXAM 2 INSTRUCTIONS VERSION 01 March 9, Section # and recitation time

9A. Iteration with range. Topics: Using for with range Summation Computing Min s Functions and for-loops A Graphics Applications

MA FINAL EXAM Form 01 MAY 3, 2018

MA EXAM 1 INSTRUCTIONS VERSION 01 September 13, Section # and recitation time

MA EXAM 3 INSTRUCTIONS VERSION 01 April 18, Section # and recitation time

8. More on Iteration with For

MA EXAM 3 Form A April 16, You must use a #2 pencil on the mark sense sheet (answer sheet).

MA EXAM 3 Form A November 12, You must use a #2 pencil on the mark sense sheet (answer sheet).

MA FINAL EXAM Form A MAY 1, 2017

MA FINAL EXAM INSTRUCTIONS VERSION 01 December 13, Section # and recitation time

MA162 EXAM III SPRING 2017 APRIL 11, 2017 TEST NUMBER 01 INSTRUCTIONS:

CS Exam 1 Study Guide and Practice Exam

MATH 1B03: Midterm 1 - VERSION 1 Instructor: Adam Van Tuyl Date: October 4, :00PM Duration: 75 min.

8.2 Examples of Classes

MA EXAM 2 INSTRUCTIONS VERSION 01 March 10, Section # and recitation time

MA EXAM 1 INSTRUCTIONS VERSION 01 FEBRUARY 8, Section # and recitation time

MA EXAM 3 INSTRUCTIONS VERSION 01 November 8, Section # and recitation time

PHYSICS 221 SPRING 2014

Read all questions and answers carefully! Do not make any assumptions about the code other than those that are clearly stated.

Physics I Exam 1 Spring 2015 (version A)

PHYSICS 111 SPRING EXAM 1: February 6, 2017; 8:15pm - 9:45pm

4.4 The Calendar program

CSE 105 THEORY OF COMPUTATION

Announcements Monday, September 18

L435/L555. Dept. of Linguistics, Indiana University Fall 2016

PHYS.1410 Physics I Exam 1 Spring 2016 (version A)

Physics I Exam 1 Fall 2015 (version A)

PHYSICS 221 SPRING EXAM 1: February 20, 2014; 8:15pm 10:15pm

PHYSICS 221 SPRING 2013

PHYSICS 221 Fall 2016 EXAM 2: November 02, :15pm 10:15pm. Name (printed): Recitation Instructor: Section #:

MA EXAM 3 Green April 11, You must use a #2 pencil on the mark sense sheet (answer sheet).

PHYSICS 221 SPRING 2015

PHYSICS 221 Fall 2013 EXAM 2: November 6, :15pm 10:15pm. Name (printed): Recitation Instructor: Section #:

MA FINAL EXAM Form B December 13, 2016

Physics 101 Hour Exam 1 March 3, 2014

10. The GNFA method is used to show that

Problem # Number of points 1 /20 2 /20 3 /20 4 /20 5 /20 6 /20 7 /20 8 /20 Total /150

CS1800 Discrete Structures Spring 2018 February CS1800 Discrete Structures Midterm Version A

MA Final Exam - Version 01 Fall 2015 VERSION 01

PHYSICS 221 SPRING EXAM 1: February 16, 2012; 8:00pm 10:00pm

Midterm 3 Thursday April 13th

PHYSICS 111 SPRING EXAM 2: March 6, 2018; 8:15-9:45 pm

ω = k/m x = A cos (ωt + ϕ 0 ) L = I ω a x = ω 2 x P = F v P = de sys J = F dt = p w = m g F G = Gm 1m 2 D = 1 2 CρAv2 a r = v2

MA FINAL EXAM Green May 5, You must use a #2 pencil on the mark sense sheet (answer sheet).

PHYSICS 221 SPRING EXAM 1: February 21, 2013; 8:15pm 10:15pm

PHYSICS 111 SPRING EXAM 2: March 8, 2016; 8:15-9:45 pm

6.01: Introduction to EECS I. Discrete Probability and State Estimation

CS-141 Exam 2 Review October 19, 2016 Presented by the RIT Computer Science Community

The exam is closed book, closed calculator, and closed notes except your one-page crib sheet.

Sample Math 115 Midterm Exam Spring, 2014

CSE20: Discrete Mathematics

MA 161 EXAM 3 GREEN November 14, You must use a #2 pencil on the scantron sheet (answer sheet).

MA EXAM 1 Form A February 4, You must use a #2 pencil on the mark sense sheet (answer sheet).

Math 20 Spring Discrete Probability. Midterm Exam

Admin. ! Will post sample questions soon. 1. Choose a bit-length k. 2. Choose two primes p and q which can be represented with at most k bits

Physics 214 Midterm Exam Spring Last Name: First Name NetID Discussion Section: Discussion TA Name:

Introduction to Probability, Fall 2009

MA/OR/ST 706: Nonlinear Programming Midterm Exam Instructor: Dr. Kartik Sivaramakrishnan INSTRUCTIONS

MA FINAL EXAM Form 01 May 1, 2017

Form #425 Page 1 of 6

You have 3 hours to complete the exam. Some questions are harder than others, so don t spend too long on any one question.

MA EXAM 1 Green February 8, You must use a #2 pencil on the mark sense sheet (answer sheet).

8.3. SPECIAL METHODS 217

ω = k/m x = A cos (ωt + ϕ 0 ) L = I ω a x = ω 2 x P = F v P = de sys J = F dt = p w = m g F G = Gm 1m 2 D = 1 2 CρAv2 a r = v2

Physics I Exam 2 Spring 2015 (version A)

6.001 Recitation 22: Streams

UC Berkeley, CS 174: Combinatorics and Discrete Probability (Fall 2008) Midterm 1. October 7, 2008

Physics I Exam 1 Fall 2014 (version A)

Carleton University. Final Examination Fall DURATION: 2 HOURS No. of students: 275

Last Name: First Name Network-ID Discussion Section: Discussion TA Name: Write your seat number on the answer sheet

PHYSICS 218 EXAM 1 Thursday, September 22, 2011

STUDENT NAME: STUDENT SIGNATURE: STUDENT ID NUMBER: SECTION NUMBER RECITATION INSTRUCTOR:

Practice Midterm Exam

STAT 516 Midterm Exam 3 Friday, April 18, 2008

Physics UCSB Winter 2015 First Midterm Exam Tuesday 1/27/2015

Announcements Wednesday, September 20

CS 591, Lecture 9 Data Analytics: Theory and Applications Boston University

Physics 101 Hour Exam 3 December 2, 2013

f 3 9 d e a c 6 7 b. Umail umail.ucsb.edu

EENG/INFE 212 Stacks

Midterm 3 Thursday April 13th

PHYSICS 111 SPRING FINAL EXAM: May 2, 2017; 2:15pm - 4:15pm

PHYS 272 (Spring 2018): Introductory Physics: Fields Homeworks

PHYSICS 111 SPRING EXAM 3: April 12, 2016; 8:15pm - 9:45pm

CS 170 Algorithms Fall 2014 David Wagner MT2

Python. chrysn

CSE 105 Theory of Computation Professor Jeanne Ferrante

Outline. policies for the second part. with answers. MCS 260 Lecture 10.5 Introduction to Computer Science Jan Verschelde, 9 July 2014

Physics Grading Sheet.

This is a closed book exam. You have ninety (90) minutes to complete it.

PHYSICS 221 SPRING EXAM 2: March 30, 2017; 8:15pm 10:15pm

Object Oriented Programming for Python

PHYSICS 221 Fall 2007 EXAM 2: November 14, :00pm 10:00pm

Welcome to Physics 211! General Physics I

Transcription:

CS177 Spring 2015 Midterm 2 April 02, 8pm-9pm There are 25 multiple choice questions. Each one is worth 4 points. Answer the questions on the bubble sheet given to you. Only the answers on the bubble sheet will be counted. The questions will be discarded. Programmable calculators cannot be used. This exam contains 19 pages (including this cover page) Remember to fill in the following bubble card fields: Student ID: Use the 10 digit ID number on your student ID card. Do not use your social security number. Last Name and First Name Test/Quiz: 02, Course: 177 Instructor: Your recitation TA s last name. Find it in the table below: Section number: Your recitation section number. Find it in the table below: Recitation Time TA Recitation Section Number R01 Thursday, 07:30 am-08:20 am Rohit Bhatia 0001 R02 Thursday, 09:30 am-10:20 am Ruby Tahboub 0002 R03 Friday, 07:30 am-08:20 am Ajay M S 0003 R04 Friday, 10:30 am-11:20 am Haining Chen 0004 R05 Friday, 12:30 pm-01:20 pm Rohit Bhatia 0005 R06 Friday, 02:30 pm-03:20 pm Adib Rastegarnia 0006 R07 Friday, 04:30 pm-05:20 pm Sait Celebi 0007 Y01 Distance learning Wei Chuang 0008 Recitation Section Number: Student Last Name: Student First Name:

CS177 Spring 2015 Midterm 2 - Page 2 of 19 April 02, 8pm-9pm 1. What is the output of the following Python program? def myfunc( matrix ) : x = matrix [ 0 ] [ 0 ] for i in range ( len ( matrix ) ) : for j in range ( len ( matrix [ 0 ] ) ) : i f i == j and x < matrix [ i ] [ j ] : x = matrix [ i ] [ j ] print ( x ) matrix = [ [ 5, 0, 10, 2 0 ], [ 7, 0, 17, 3 ], [ 3, 4, 9, 1 5 ], [ 1, 2, 6, 1 1 ] ] myfunc( matrix ) A. 0 B. 1 C. 11 D. 17 E. 20

CS177 Spring 2015 Midterm 2 - Page 3 of 19 April 02, 8pm-9pm 2. What is the output of the following Python program? try : a = 1 / 0 except Z e r o D i v i s i o n E r r o r : print ( ZeroDiv ) except : print ( DefaultExcep ) else : print ( Else ) f i n a l l y : print ( F i n a l l y ) A. ZeroDiv B. Else C. DefaultExcep D. ZeroDiv Finally E. ZeroDiv DefaultExcep Finally

CS177 Spring 2015 Midterm 2 - Page 4 of 19 April 02, 8pm-9pm 3. For which values of A, B and C does the following statement evaluate to False? not ( A!= C and B ) and not ( C == 1 or A == 2 ) A. A = 3 B = False C = 4 B. A = 1 B = False C = 2 C. A = 5 B = True C = 5 D. A = 0 B = False C = 2 E. A = 1 B = False C = A

CS177 Spring 2015 Midterm 2 - Page 5 of 19 April 02, 8pm-9pm 4. What is the output of the following Python program? def func ( l i s t ) : for i in range ( 4, 1, 1) : l i s t [ i +1] = l i s t [ i ] for i in range ( len ( l i s t ) ) : print ( l i s t [ i ], end= ) l i s t = [ A, B, C, D, E, F ] func ( l i s t ) A. A B C D E F B. A B C D E E C. B C D E F F D. A A B C D E E. B B C D E F 5. What is the output of the following Python program? A=[ abcde, f g h i j, klmno, pqrst, uvwxyz ] print (A [ 2 ] [ 1 : ] ) A. fghij B. k C. l D. lmno E. f

CS177 Spring 2015 Midterm 2 - Page 6 of 19 April 02, 8pm-9pm 6. Which of the following Python programs will result in an infinite loop? I. i = 0 while i < 100: i = i + 10 print ( i ) II. i = 100 while i > 0 : i = i + 10 print ( i ) III. i = 100 while i > 0 : i = i 10 print ( i ) IV. i = 1 while i <= 100: i = i + 10 print ( i ) A. I B. II C. III D. IV E. None of the above

CS177 Spring 2015 Midterm 2 - Page 7 of 19 April 02, 8pm-9pm 7. What is the output of the following Python code? var = 0 i = 15 while ( i > 1 ) : var = var + i i = i 6 print ( i, var ) A. 3 27 B. -3 27 C. -3 21 D. -3 33 E. 3 33 8. How many times is j printed in the following Python program? for i in range ( 5 ) : for j in range ( i ) : print ( j ) A. 1 B. 3 C. 6 D. 10 E. 15

CS177 Spring 2015 Midterm 2 - Page 8 of 19 April 02, 8pm-9pm 9. What is the output of the following Python program? A= [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] for i in range ( len (A[ 0 ] ) ) : for j in range ( len (A) ) : A[ j ] [ i ] = A[ i ] [ j ] print (A) A. [[-1, -4, -7], [-2, -5, -8], [-3, -6, -9]] B. [[-1, 2, 3], [4, -5, 6], [7, 8, -9]] C. [[1, 2, 3], [4, 5, 6], [7, 8, 9]] D. [[-1, 2, 3], [-2, -5, 6], [-3, -6, -9]] E. [[3, 2, 1], [6, 5, 4], [9, 8, 7]] 10. What is the output of the following Python program? sumvalue = 1 while sumvalue < 5 0 : sumvalue = sumvalue 2 print ( sumvalue ) A. 16 B. 32 C. 64 D. 128 E. 256

CS177 Spring 2015 Midterm 2 - Page 9 of 19 April 02, 8pm-9pm 11. What is the output of the following Python program? def myfunc( x ) : i = 0 while i < len ( x ) : i f x [ i ] % 2 == 1 : print ( x [ i ] ) break i = i + 1 x = [ 0, 2, 3, 5, 6, 9 ] myfunc( x ) A. 0 B. 2 C. 3 D. 5 E. 6 12. Which of the following statements are true: A. If a break statement is reached in a nested loop, the current loop and all loops containing the current loop are exited. B. If a break statement is reached in a loop, execution is continued immediately after the break statement. C. If a break statement is reached in a loop, the loop is exited. D. If a break statement is reached in a for loop, execution is continued with the next iteration of the for loop after incrementing the for loop index variable. E. A break statement can exit from a function.

CS177 Spring 2015 Midterm 2 - Page 10 of 19 April 02, 8pm-9pm 13. How many times is the print statement executed in the following program? for i in range ( 5 ) : j = 0 while True : i f j > i : break ; print ( i j ) j = j + 1 A. 0 B. 1 C. 15 D. 20 E. 25 14. What is the output of the following Python program? def f i l t e r n u m b e r s ( numbers, n) : r e s u l t s = [ ] for number in numbers : i f number % n : r e s u l t s. append ( number ) return r e s u l t s def main ( ) : r e s u l t s = f i l t e r n u m b e r s ( range (0, 10), 2) print ( r e s u l t s ) main ( ) A. [2, 4, 6, 8, 10] B. [0, 2, 4, 6, 8] C. [1, 3,5, 7] D. [1, 3, 5, 7, 9] E. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

CS177 Spring 2015 Midterm 2 - Page 11 of 19 April 02, 8pm-9pm 15. What is the output of the following Python program? def search ( numbers ) : found = False index = 0 while index < len ( numbers ) and found == False : i f ( numbers [ index ]%2 == 0) and ( numbers [ index ]%3 == 0) : found = True else : index = index + 1 return index, numbers [ index ] print ( search ( range (2, 9) ) ) print ( search ( range (10, 16) ) ) A. (4, 6) (2, 12) B. (3, 5) (1, 12) C. (3, 5) (2, 12) D. (4, 6) (1, 12) E. (1, 3) (5, 15)

CS177 Spring 2015 Midterm 2 - Page 12 of 19 April 02, 8pm-9pm 16. What is the output of the following Python program? def mix (num, word ) : i f word [ 2 ] == r : return 2 num e l i f num > 1 0 : return ( word + word ) e l i f word [ 0 : 2 ] == CS : return (4 == 5) def main ( ) : print ( mix (15, Purdue ) ) print ( mix (10, CS177 ) ) main ( ) A. PurduePurdue False B. PurduePurdue True C. PurduePurdue PurduePurdue D. 30 True E. 30 False

CS177 Spring 2015 Midterm 2 - Page 13 of 19 April 02, 8pm-9pm 17. What is the output of the following Python program? def Test ( s ) : wordslist = s news = for i in range ( len ( wordslist ) 1, 1, 1) : i f i > 0 : news = news + wordslist [ i ] else : news = news + wordslist [ i ] return news def main ( ) : print ( Test ( Purdue ) ) main ( ) A. Purdue B. eudrup C. eudru D. urdue E. udrup

CS177 Spring 2015 Midterm 2 - Page 14 of 19 April 02, 8pm-9pm 18. What is the output of the following Python program? number = 25 isprime = True i = 2 while i < number and isprime : i f number % i == 0 : isprime = False i += 1 print ( i i s, i, isprime i s, isprime ) A. i is 5 isprime is True B. i is 5 isprime is False C. i is 2 isprime is True D. i is 6 isprime is True E. i is 6 isprime is False 19. What is the output of the following Python program? def hcf ( x, y ) : i f x > y : s m a l l e r = y else : s m a l l e r = x for i in range (1, s m a l l e r + 1) : i f ( ( x % i == 0) and ( y % i == 0) ) : hcf = i print ( hcf ) def main ( ) : hcf (15,35) main ( ) A. 3 B. 4 C. 5 D. 9 E. 12

CS177 Spring 2015 Midterm 2 - Page 15 of 19 April 02, 8pm-9pm 20. Which of the following Python program will print Woof woof!! on the screen? class Dog : def i n i t ( s e l f, name) : s e l f. name = name def bark ( s e l f ) : print ( Woof woof!! ) A. bark ( ) B. Dog. bark ( ) C. d = Dog( golden ) d.bark() D. d = Dog ( ) d. bark ( ) E. d = Dog ( ) d. bark ( d )

CS177 Spring 2015 Midterm 2 - Page 16 of 19 April 02, 8pm-9pm 21. What is the output of the following Python program? class Car : def i n i t ( s e l f, color, model ) : s e l f. c o l o r = c o l o r s e l f. model = model def update ( s e l f, color, model ) : c o l o r = c o l o r s e l f. model = model def printcar ( s e l f ) : print ( This i s a +s e l f. c o l o r+ +s e l f. model +. ) car1 = Car ( red, F e r r a r i ) car1. update ( blue, Porsche ) car1. printcar ( ) A. This is a red Porsche. B. This is a blue Porsche. C. This is a red Ferrari. D. This is a blue Ferrari. E. Error 22. What is the output of the following Python program? class Account : def i n i t ( s e l f, id ) : s e l f. id = id id = 666 id = s e l f. id + id acc = Account (123) print ( acc. id ) A. 0 B. 123 C. 666 D. 789 E. Error

CS177 Spring 2015 Midterm 2 - Page 17 of 19 April 02, 8pm-9pm 23. What is the output of the following Python program? class A: def i n i t ( s e l f ) : print ( In i n i t ) def getnumber ( s e l f, number, str ) : s e l f. number = number + 1 s e l f. str = str. c a p i t a l i z e ( ) return INIT a = A( ) var = getnumber ( a, 10, number ) print ( var. number ) print ( var. str ) A. The program does not run and gives an error straight away B. The program first prints In init and then throws an error C. The program gives NameError: number and str not defined D. 11 number E. 11 Number

CS177 Spring 2015 Midterm 2 - Page 18 of 19 April 02, 8pm-9pm 24. Which of the following statements is correct for the following Python program (the intended behavior is that it prints the string Welcome )? class A: def i n i t ( s e l f, s ) : s e l f. s = s def myprint ( s e l f ) : print ( s ) a = A( Welcome ) a. myprint ( ) A. The program doesn t run as expected because class A does not have a constructor. B. The output of the above program is Welcome, that is, it runs as expected C. The program doesn t run as expected because class A should have the myprint function defined as: def myprint ( s e l f, s ) : print ( s e l f+s ) D. The program doesn t run as expected because class A should have the myprint function defined as: def myprint ( s ) : print ( s ) E. The program doesn t run as expected because class A should have the myprint function defined as: def myprint(self): print(self.s)

CS177 Spring 2015 Midterm 2 - Page 19 of 19 April 02, 8pm-9pm 25. What is the output of the following Python program? import random def cointoss ( number ) : heads = 0 t a i l s = 0 for i in range ( number ) : f l i p = random. randint ( 1, 2 ) i f ( f l i p == 1) : heads = heads + 1 else : t a i l s = t a i l s + 1 return heads, t a i l s def main ( ) : heads, t a i l s = cointoss (10) print ( heads ) print ( t a i l s ) main ( ) A. 5 5 B. 4 6 C. 6 4 D. 7 3 E. Any of the above 4 outputs is possible