Exam 2, Form A CSE 231 Spring 2014 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Similar documents
Exam 2, Form B CSE 231 Spring 2014 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Exam #3, Form 3 A CSE 231 Fall 2015 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Fall 08, Sherri Goings, Exam #1 (10/2), form 1 B

First name (printed): a. DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Exam 3, Form A CSE 231 Spring 2014 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Spring Semester 13, Dr. Punch. Exam #1 (2/14), form 1 A

Exam #1, Form 1 A CSE 231 Spring 2015 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Spring Semester 11 Exam #1 Dr. Dillon. (02/15)

Final Exam, Form 3 A CSE 231 Spring 2015 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Spring Semester 09 Exam #1 Dr. Dillon. (02/19)

Spring Semester 08, Dr. Punch. Exam #1 (2/12), form 1 B

Spring Semester 10 Exam #1 Dr. Dillon. (02/18)

Spring Semester 09 Exam #2 Dr. Dillon. (04/02)

Spring Semester 08, Dr. Punch. Exam #1 (2/12), form 1 A

Exam 1, Form A CSE 231 Fall 2012 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Exam 2, Form A CSE 231 Spring 2013 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Spring Semester, Dr. Punch. Exam #2 (03/28), form 2 C

First name (printed): a. DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Spring Semester 16, Dr. Punch. Exam #1 (2/18), form 1 A

Fall Semester, Dr. Punch. Exam #2 (11/07), form 2 A

CS 2316 Exam 1 Spring 2014

Lecture 7. Memory in Python

Practice midterm exam

CMSC330 Fall 2016 Midterm #1 2:00pm/3:30pm

CS 1301 Exam 1 Spring 2015

CS 1301 Exam 1 Fall 2014

CSSE 120 Introduction to Software Development Practice for Test 1 paper-and-pencil part Page 1 of 6

CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, Good Luck!

Final Exam Version A

Lists, loops and decisions

Name Feb. 14, Closed Book/Closed Notes No electronic devices of any kind! 3. Do not look at anyone else s exam or let anyone else look at yours!

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Comp Exam 1 Overview.

CS 1301 Exam 3 Spring 2014

Version B Final Exam

CS Name : Grading TA:

CS 2316 Exam 1 Spring 2013

Homework notes. Homework 2 grades posted on canvas. Homework 3 due tomorrow. Homework 4 posted on canvas. Due Tuesday, Oct. 3

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

CS 1301 Exam 1 Fall 2014

Functions, Scope & Arguments. HORT Lecture 12 Instructor: Kranthi Varala

CSE341, Spring 2013, Final Examination June 13, 2013

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

Announcements. Lecture Agenda. Class Exercise. Hashable. Mutability. COMP10001 Foundations of Computing Iteration

CS 1110 Prelim 1 October 15th, 2015

In addition to the correct answer, you MUST show all your work in order to receive full credit.

CS112 Spring 2012 Dr. Kinga Dobolyi. Exam 2. Do not open this exam until you are told. Read these instructions:

CS 1301 Exam 1 Spring 2014

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1

Final Exam(sample), Fall, 2014

CSE341 Spring 2017, Final Examination June 8, 2017

CS 1301 Exam 1 Fall 2011

EXAMINATION INSTRUCTIONS

: Intro Programming for Scientists and Engineers Final Exam

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY

Module 04: Lists. Topics: Lists and their methods Mutating lists Abstract list functions Readings: ThinkP 8, 10. CS116 Fall : Lists

CS 111X - Fall Test 1

Class extension and. Exception handling. Genome 559

LISTS WITH PYTHON. José M. Garrido Department of Computer Science. May College of Computing and Software Engineering Kennesaw State University

University of Maryland College Park Dept of Computer Science CMSC106 Fall 2016 Midterm I

Part III Appendices 165

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

Python Programming. Introduction Part II

UNIVERSITY OF TORONTO Faculty of Arts and Science. Midterm 1 CSC148H1F L0201 (Liu)

CSE341 Spring 2017, Final Examination June 8, 2017

EXAMINATION INSTRUCTIONS

CS 1301 Exam 1 Spring 2011

Short Answer Questions (40 points)

Control Structures 1 / 17

Class extension and. Exception handling. Genome 559

GIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes

Structure and Interpretation of Computer Programs

CS 1301 Exam 2 Fall 2010

PREPARING FOR PRELIM 1

1 Fall 2017 CS 1110/1111 Exam 3

CS 100 Fall 2012 Final

Sample Final Exam Questions

Exam 1 Practice CSE 232 Summer 2018 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

CSE341 Autumn 2017, Final Examination December 12, 2017

Exception Handling. Genome 559

CIS192: Python Programming

MORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page.

CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees. CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees 1

Please write your answers clearly and neatly we can t give you credit if we can t decipher what you ve written.

STEAM Clown & Productions Copyright 2017 STEAM Clown. Page 1

Welcome to CSC148! Introduction to Computer Science

Today: Revisit some objects. Programming Languages. Key data structure: Dictionaries. Using Dictionaries. CSE 130 : Winter 2009

Programming Languages

Final Exam Practice Questions

Lecture 12. Lists (& Sequences)

Next: What s in a name? Programming Languages. Data model in functional PL. What s in a name? CSE 130 : Fall Lecture 13: What s in a Name?

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

Outline. The Python Memory Model A Linked Implementation of Lists In-Class Work. 1 Chapter 4: Linked Structures and Iterators

CIS 110 Introduction to Computer Programming Summer 2016 Midterm. Recitation # (e.g., 201):

CS1110 Lab 6 (Mar 17-18, 2015)

Introduction to Python (All the Basic Stuff)

CSE 143 Final Exam Part 1 - August 18, 2011, 9:40 am

Lists How lists are like strings

Transcription:

Name: Section: Date: INSTRUCTIONS: (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN. (2) This exam booklet contains 30 questions, each of which will be weighted equally at 5 points each. The total points for the exam is 150 points. (3) You may use one 8.5 x 11 note sheet during the exam. No other reference materials or electronic devices may be used during the examination, i.e. no calculators, cell phones, mp3 players, etc. Paper dictionaries are allowed. (4) Questions will not be interpreted during the examination. (5) You should choose the single best alternative for each question, even if you believe that a question is ambiguous or contains a typographical error. If a question has more than one best answer, credit will be given for any of the correct answers. Provide only one answer. (6) Please fill in the requested information at the top of this exam booklet. (7) Use a #2 pencil to encode answers on the OMR form. (8) Please encode the following on the OMR form: Last name and first initial MSU PID Exam form (2 A) (9) Please sign the OMR form. (10) Only answers recorded on your OMR form will be counted for credit. Completely erase any responses on the OMR form that you wish to delete. (11) You must turn in this exam booklet, the OMR form, your note sheet, and your scrap paper when you have completed the exam. Be sure your name is on any of these items that you would like to have returned. (12) The exam ends at 2:00 pm. When leaving, please be courteous to those still taking the exam.

1 2 3 4 5 6 7 8 9 10 D A C C A D A D A B 11 12 13 14 15 16 17 18 19 20 C A E C D C A B E A 21 22 23 24 25 26 27 28 29 30 C B B A C A D * B D Error in Q13: extra comma before the assignment was not intended. Either (d) or (e) given full credit (but correct answer is (e)). Error in Q19: print instruction removed from the program, but the output it produced was mistakenly left in the answer. Either (b) or (e) given full credit (but correct answer is (e)). Q24: partial credit (2 pts) for marking (b); for (b) to be correct, the function would need a return instruction, e.g. return par Q28: this question was thrown out because of poor wording. (c) was poorly worded: in fact, assignment does not return a value --- that is subtlely different from returning None. So none of the alternatives is technically correct. Any answer was accepted for this question. (Including no answer.)

a = [1] * 5 print( a ) # Line 1 a = list( range( 2 ) ) print( a ) # Line 2 a *= 3 print( a ) # Line 3 Figure 1 (1) In Fig. 1, what is displayed by the line labeled Line 1? (a) [5, 5, 5, 5, 5] (b) 5 (c) [5] (d) [1, 1, 1, 1, 1] (e) None of (a) (e) (2) In Fig. 1, what is displayed by the line labeled Line 2? (a) [0, 1] (b) [1, 2] (c) [0, 1, 0, 1, 0, 1] (d) [1, 2, 1, 2, 1, 2] (e) None of (a) (e) (3) In Fig. 1, what is displayed by the line labeled Line 3? (a) [1, 2] (b) [1, 2, 1, 2, 1, 2] (c) [0, 1, 0, 1, 0, 1] (d) [0, 3] (e) None of (a) (e) c = [] for n in range( 3 ): c.append( 10 * n - 2 ) print( c ) Figure 2 (4) In Fig. 2, what is displayed? (a) 24 (b) [8, 18, 28] (c) [-2, 8, 18] (d) [0.01, 0.1, 1] (e) None of (a) (e)

b = [ let, bygones, be ] print( b in b ) # Line 1 print(.join(b) ) # Line 2 print( b ) # Line 3 print( b[1:-1] ) # Line 4 print( b[1][-1] ) # Line 5 b.sort() print( b ) # Line 6 Figure 3 (5) In Fig. 3, what is displayed by the line labeled Line 1? (a) False (b) b in [ let, bygones, be ] (c) True (d) None of (a) (c) (6) In Fig. 3, what is displayed by the line labeled Line 2? (a) [ let, bygones, be ] (b) [ be, bygones, let ] (c) letbygonesbe (d) let bygones be (7) In Fig. 3, what is displayed by the line labeled Line 3? (a) [ let, bygones, be ] (b) let bygones be (c) letbygonesbe (d) [ be, bygones, let ] (8) In Fig. 3, what is displayed by the line labeled Line 4? (a) [ be, bygones ] (b) [ be, bygones, let ] (c) [ bygones, be ] (d) [ bygones ] (9) In Fig. 3, what is displayed by the line labeled Line 5? (a) s (b) [ s ] (c) t (d) [ bygones ] (10) In Fig. 3, what is displayed by the line labeled Line 6? (a) [ let, bygones, be ] (b) [ be, bygones, let ] (c) letbygonesbe (d) let bygones be

def foo( x = 4, y = -1 ): x = x - y y = 2 * x return x + y x, y = 1, 2 z = foo( x, y ) print( x, y, z ) # Line 1 x, y = 3, 2 z = foo( y ) print( x, y, z ) # Line 2 x, y, = 2, 5 z = foo( y = x ) print( x, y, z ) # Line 3 Figure 4 (11) In Fig. 4, what is displayed by the line labeled Line 1? (a) 5 10 15 (b) -1-2 -3 (c) 1 2-3 (d) 1 2 15 (e) None of (a) (e) (12) In Fig. 4, what is displayed by the line labeled Line 2? (a) 3 2 9 (b) 3 2-3 (c) 3 2 6 (d) -1-2 -3 (e) None of (a) (e) (13) In Fig. 4, what is displayed by the line labeled Line 3? (a) 2 5 9 (b) 2 4 9 (c) 3 6 6 (d) 2 5 6 (e) None of (a) (e) (14) In Fig. 4, which name is not in scope in the body (suite) of function foo? (a) x (b) y (c) z (d) foo (e) None of (a) (e)

s0 = set() for i in [2, 3, 9, 5]: s0 = s0 { i%3 } print(s0) # Line 1 s1 = set( range( 1, 6, 2 ) ) s2 = set( [ 3*n - 1 for n in range(3) ] ) print(s1 & s2) # Line 2 print(s2 - s1) # Line 3 print ( (s1 & s2) < (s1 s2) ) # Line 4 Figure 5 (15) In Fig. 5, what is displayed by the line labeled Line 1? (a) {0, 1, 3} (b) {2, 3, 9, 5} (c) {} (d) {0, 2} (16) In Fig. 5, what is displayed by the line labeled Line 2? (a) {} (b) {-1, 2, 3, 5} (c) {5} (d) {-1, 2, 3} (17) In Fig. 5, what is displayed by the line labeled Line 3? (a) {2, -1} (b) {3, 1} (c) {} (d) {3, -1, 2} (18) In Fig. 5, what is displayed by the line labeled Line 4? (a) False (b) True (c) None of (a) (b)

def get value( prompt ): value str = input( prompt ) try: value = float( value str ) except ValueError: print ( "** Invalid input **" ) value = 0 return value def main(): try: val1 = get value( "Enter the 1st value: " ) val2 = get value( "Enter the 2nd value: " ) print( round(val1/val2, 1) ) except ZeroDivisionError: print( "** Invalid **" ) main() print( "" ) Figure 6 (19) In Fig. 6, what is displayed if the user enters 2 at the first prompt and 3 at the second? (a) Enter the 1st value: 2 (b) Enter the 1st value: 2 Enter the 2nd value: 3 Enter the 2nd value: 3 2.0 / 3.0: 0.7 2.0 / 3.0: 0.7 (c) Enter the 1st value: 2 Enter the 2nd value: 3 2 / 3: 0.7 (d) Enter the 1st value: 2 Enter the 2nd value: 3 2 / 3: 0.6

(20) In Fig. 6, what is displayed if the user enters 2 at the first prompt and 3 at the second (with the quotes)? (a) Enter the 1st value: 2 ** Invalid input ** Enter the 2nd value: 3 ** Invalid input ** ** Invalid ** (b) Enter the 1st value: 2 Enter the 2nd value: 3 2.0 / 3.0: 0.7 (c) Enter the 1st value: 2 ** Invalid input ** Enter the 2nd value: 3 ** Invalid input ** (d) Enter the 1st value: 2 ** Invalid input ** Enter the 2nd value: 3 ** Invalid input ** Invalid (21) In Fig. 6, what is displayed if the user enters 2.3 at the first prompt and 0 at the second? (a) Enter the 1st value: 2.3 (b) Enter the 1st value: 2.3 ** Invalid input ** Enter the 2nd value: 0 Enter the 2nd value: 0 ** Invalid input ** ** Invalid input ** 0.0 / 2.3: 0.0 ** Invalid ** (c) Enter the 1st value: 2.3 Enter the 2nd value: 0 ** Invalid ** (d) Enter the 1st value: 2.3 Enter the 2nd value: 0 ** Invalid **

(22) In Fig. 6, what is displayed if the user enters 0 at the first prompt and two at the second? (a) Enter the 1st value: 0 (b) Enter the 1st value: 0 ** Invalid input ** Enter the 2nd value: two Enter the 2nd value: two ** Invalid input ** ** Invalid input ** ** Invalid ** ** Invalid ** (c) Enter the 1st value: 0 Enter the 2nd value: two 0.0 / 2.0: 0.0 (d) Enter the 1st value: 0 Enter the 2nd value: two 0 / 2: 0 # remember mutable vs. immutable! def fun1( par, num ): par[0] = num a1 = [ a, b, c ] a2 = fun1( a1, 2 ) print(a1) # Line 1 print(a2) # Line 2 def fun2 (p1,p2): p1 = p1[::-1] p2 = max(p2) + min(p2) return p1, p2 t1 = ( a, b ) t2 = ( A, B ) a,b = fun2(t1,t2) print(a) # Line 3 print(b) # Line 4 print(t2) # Line 5 Figure 7

(23) In Fig. 7, what is displayed by the line labeled Line 1? (a) None (b) [2, b, c ] (c) [ a, b, c ] (d) [ a ] (24) In Fig. 7, what is displayed by the line labeled Line 2? (a) None (b) [2, b, c ] (c) [ a, b, c ] (d) [ a ] (25) In Fig. 7, what is displayed by the line labeled Line 3? (a) ( a, b ) (b) [ b, a ] (c) ( b, a ) (d) [b] (26) In Fig. 7, what is displayed by the line labeled Line 4? (a) BA (b) B (c) A (d) [ba] (27) In Fig. 7, what is displayed by the line labeled Line 5? (a) AB (b) ( B, A ) (c) BA (d) ( A, B ) (28) Which of the following is correct? (a) Python is an interpreted language. (b) The Python assignment instruction produces a side effect. (c) The Python assignment instruction returns None. (d) All of (a) (c) are correct. (e) None of (a) (c) are correct.

import string def dissemble(d, w): for c in w: if c in d: if w not in d[c]: d[c].append(w) else: d[c] = [w] s str = A man. A plan. s lst = s str.split() w lst = [w.strip(string.punctuation).lower() for w in s lst] data = {} for w in w lst: dissemble(data, w) if n in data: # first if print( sorted( data[ n ] ) ) else: print( "Not there." ) if. in data: # second if print( sorted( data[. ] ) ) else: print( "Not there." ) Figure 8 (29) In Fig. 8, what is displayed by the first if statement (labeled first if)? (a) [ plan, man ] (b) [ man, plan ] (c) [ A, a, man, plan ] (d) Not there. (30) In Fig. 8, what is displayed by the second if statement (labeled second if)? (a) [ plan., man. ] (b) [ man., plan. ] (c) [ A, a, man, plan ] (d) Not there.

Scratch