CS 1110 Prelim 2 April 26th, 2016

Similar documents
Last Name: UTION First Name: SOL Cornell NetID: CS1110. Solution: CS 1110 Prelim 2 April 26, 2016

CS 1110 Prelim 1 March 15th, 2016

CS 1110 Prelim 2 April 22, 2014

CS 1110 Prelim 1 March 7th, 2013

CS 1110 Prelim 2 April 21, 2015

CS 1110 Regular Prelim 1, March 14th, 2017

CS 1110 Final Exam, May 2018

CS 1110 Final, May 2017

CS 1110 Prelim 1, March 2018

CS 1110 Prelim 1 March 10, 2015

CS 1110 Final Exam May 9th, 2013 SOLUTIONS

CS 1110 Prelim 2 November 12th, 2015

CS 1110 Prelim 2 November 14th, 2013

CS 1110 Prelim 2 November 10th, 2016

CS 1110 Prelim 2 November 12th, 2015

CS 1110 Prelim 2 November 13th, 2014

CS 1110 Prelim 1 October 15th, 2015

CS 1110 Prelim 1 October 17th, 2013

CS 1110 Prelim 2 April 21, 2015 GRADING GUIDE

CS 1110 Prelim 2 November 6th, 2012

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CS 1110 Final, December 8th, Question Points Score Total: 100

CS 1110 Prelim 1 October 12th, 2017

Student Number: Comments are not required except where indicated, although they may help us mark your answers.

Last Name: First: Netid: Section. CS 1110 Final, December 17th, 2014

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Assignment 7: Due Wednesday May 11 at 6pm UPDATES on Monday May 9

CS1110 Lab 6 (Mar 17-18, 2015)

CS 1110 Final, December 8th, Question Points Score Total: 100

CS 1110 Prelim 1 March 7th, 2013 SOLUTIONS

CS 1110 Final, December 17th, Question Points Score Total: 100

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CS 4620 Midterm, March 21, 2017

CS 1110 Prelim 1 October 4th, 2012

CS 1110 Final, December 16th, 2013

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

CS 1110 Final, December 16th, 2013

Last Name: First Name: Cornell NetID, all caps: CS 1110 Regular Prelim 1 Solutions March 2018

UTORid: Lecture Section: (circle one): L0101 (MWF10) L0201 (MWF11) Instructor: Jacqueline Smith Jen Campbell

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CS 1110 Final, December 9th, Question Points Score Total: 100

Review 2. Classes and Subclasses

PREPARING FOR PRELIM 1

15-110: Principles of Computing, Spring 2018

Final Exam. COMP Summer I June 26, points

Student Number: Comments are not required except where indicated, although they may help us mark your answers.

CS Prelim 1 Review Fall 2017

CS Prelim 1 Review Fall 2013

Duration: 90 minutes. Page 1 of 14 Q2: /13 Q3: /13 TOTAL: /38. Bonus /1

CS 1110 Prelim 2 Solutions April 2018

Structure and Interpretation of Computer Programs

CS Prelim 1 Review Fall 2018

COS 126 General Computer Science Spring Written Exam 1

Preliminary Examination I Computer Science 312, Cornell University 6 March 2003

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

UNIVERSITY OF TORONTO Faculty of Arts and Science

PREPARING FOR THE FINAL EXAM

Student Number: Instructor: Brian Harrington

Statement of integrity: I did not, and will not, violate the rules of academic integrity on this exam.

CS Prelim 1 Review Fall 2012

COS 126 General Computer Science Spring Written Exam 2

Exam 1 Format, Concepts, What you should be able to do, and Sample Problems

CS 1110 Final Exam Solutions May 2018

Structure and Interpretation of Computer Programs

UNIVERSITY OF TORONTO SCARBOROUGH. December 2017 EXAMINATIONS. CSCA20H3 Duration 3 hours. Examination Aids: Instructor: Bretscher

CS 1110, LAB 1: EXPRESSIONS AND ASSIGNMENTS First Name: Last Name: NetID:

CS1110 Lab 5: Practice for A4 (Mar 8-9, 2016) First Name: Last Name: NetID:

Question 1. December 2009 Final Examination Marking Scheme CSC 108 H1F

You may not share any information or materials with classmates during the exam and you may not use any electronic devices.

Structure and Interpretation of Computer Programs

Do not turn this page until you have received the signal to start.

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

Review 1. Call Frames; Diagramming Objects

Overview of List Syntax

Assignment 4: Due Friday Mar 11 at 6pm

Final Examination, Semester 1, 2015 COMP10001 Foundations of Computing

CS Prelim 1 Review Fall 2016

What is Recursion? 21. Recursion. The Concept of Recursion Is Hard But VERY Important. Recursive Graphics. Tiling a Triangle.

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

Acct. balance Acct. balance 50 25

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

CS 1110, LAB 3: STRINGS; TESTING

CS 1110: Introduction to Computing Using Python Lists and Sequences

CS 115 Exam 2 (Section 1) Spring 2017 Thu. 03/31/2017

Assignment 3: Due Friday Mar 4 at 6pm on CMS Updates in orange/red; last update 12:10pm Sun Feb 28

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CS8 Final Exam E03, 09M, Phill Conrad, UC Santa Barbara 09/10/2009

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

Lecture 1. Course Overview, Python Basics

UNIVERSITY OF TORONTO Faculty of Arts and Science. Midterm Sample Solutions CSC324H1 Duration: 50 minutes Instructor(s): David Liu.

CS 1110, Spring 2018: Prelim 1 study guide Prepared Tuesday March 6, 2018

Part I. Wei Tianwen. A Brief Introduction to Python. Part I. Wei Tianwen. Basics. Object Oriented Programming

CS 1110 Final Exam Solutions May 15th, 2014

CS Prelim 1 Review Fall 2013

Do not turn this page until you have received the signal to start.

Assignment 5: Due Friday April 8 at 6pm Clarification and typo correction, Sunday Apr 3 3:45pm

SOFT 161. Class Meeting 1.6

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:

Transcription:

Circle your lab/situation: CS 1110 Prelim 2 April 26th, 2016 ACCEL: Tue 12:20 Tue 1:25 Tue 2:30 Tue 3:35 ACCEL : Wed 10:10 Wed 11:15 Wed 12:20 Wed 1:25 Wed 2:30 Wed 3:35 PHILLIPS : Tue 12:20 Tue 1:25 Wed 12:20 I m a grad student and hence LABLESS This 90-minute exam has 6 questions worth a total of 34 points. When permitted to begin, scan the whole test before starting. Budget your time wisely. When asked to write Python code on this exam, you may use any Python feature that you have learned about in class. Unless otherwise stated, you may write helper functions when asked to write code, but include specifications for them in their doc strings. It is a violation of the Academic Integrity Code to look at any exam other than your own, to look at any other reference material, or to otherwise give or receive unauthorized help. We also ask that you not discuss this exam with students who are scheduled to take a later makeup. Academic Integrity is expected of all students of Cornell University at all times, whether in the presence or absence of members of the faculty. Understanding this, I declare I shall not give, use or receive unauthorized aid in this examination. Signature: Date For reference: s[i:j] Returns: A new string s[i] s[i+1]... s[j-1] under ordinary circumstances. Returns '' if i len(s) or i j. s.find(s1) Returns: index of the first character of the first occurrence of s1 in s, or 1 if s1 does not occur in s. s.index(s1) Like find, but raises an error if s1 is not found. s.lower() Returns: a copy of s with all letters in it converted to lowercase. s.count(s1) Returns: the number of non-overlapping appearances of string s1 in string s. lt[i:j] Returns: A new list[lt[i], lt[i+1],..., lt[j-1]] under ordinary circumstances. Returns [] if i len(lt) or i j. lt.index(item) Returns: index of first occurrence of item in list lt; raises an error if item is not found. range(n) Returns: the list [0, 1, 2,..., n-1] x in lt Returns: True if x is in list or string lt, False otherwise. lt.append(x) Append object x to the end of list lt. lt.sort() Sort the items of lt, in place (the list is altered).

... Question Points Score 1 6 2 4 3 11 4 6 5 6 6 1 Total: 34 Page 2

1. [6 points] What is the output if the following module is run: def F1(x): y = [] # empty list n = len(x) for k in range(n): if k==0 or k==n-1: y.append(x[k]) else: y.append(x[k-1]+x[k+1]) return y def F2(x): y = x n = len(x) for k in range(n): if k==0 or k==n-1: y[k] = x[k] else: y[k] = x[k-1]+x[k+1] if name == ' main ': x = ["A","B","C","D"] z = F1(x) print x print z print "..." x = ["A","B","C","D"] z = F2(x) print x print z Page 3

2. [4 points] What is the output if the following module is run? class C(object): def init (self,u,v): self.x = u self.y = v def Reflect1(self): temp = self.x self.x = self.y self.y = temp def Reflect2(self): temp = self.x self.x = self.y self.y = temp z = self return z if name == ' main ': x = 1 y = 2 P = C(1,2) P.Reflect1() print x,y print P.x,P.y x = 1 y = 2 P = C(1,2) Q = P.Reflect2() print P.x,P.y print Q.x,Q.y No partial credit without a diagram that displays objects and references. You can put such a diagram in the whitespace to the right of the code above. Page 4

3. [11 points] Assume the availability of these classes: class Point(object): Attributes: x: float, the x-coordinate of a point y: float, the y-coordinate of a point def init (self,x,y): Creates a point. PreC: x and y are floats self.x = x self.y = y class LineSeg(object): Attribute: P1: endpoint [Point] P2: endpoint [Point] def init (self,q,r): self.p1 = Q self.p2 = R (a) Write code that assigns to variable Z a reference to a LineSeg object that represents the line segment with endpoints (1,2) and (3,4). Page 5

(b) We say that a point (a, b) is positive if a > 0 and b > 0. Write a boolean-valued method Pos for the Point class that returns True if the referenced point is positive. Your answer must include the header definition ( def Pos(... ). Omit the docstring. Page 6

(c) Complete the following function: def F(L): Returns a list of all those references in L that are to LineSeg objects whose endpoints are both positive. PreC: L is a list of references to LineSeg objects. You may assume the availability of the method Pos in part (b). Page 7

(d) Complete the following function. Nested loops are allowed. def F(LofP1,LofP2): Returns a list of references to LineSeg objects that encodes all possible line segments obtained by connecting a point in LofP1 to a point in LofP2 PreC: LofP1 and LofP2 are nonempty lists of references to Point objects. Assume that the points encoded by these lists are all distinct. Page 8

4. [6 points] Assume the availability of the following function: def randilist(l,r,n): Returns a length-n list of random integers from interval [L,R] inclusive. PreC: L,R,n ints with L<=R and n>=1 Complete the following script so that it assigns to a float variable p an estimate of the probability that when you roll three dice, exactly two of them have the same value. Your solution must make effective use of the three generated lists of random integers created in the assignment to D below. No additional calls to randilist or randi are allowed. Don t print or return p. If you choose to use a helper function, put its definition here, before your Application script code: if name == ' main ': Roll 3 dice many times and record the outcome using lists. N = 1000000 D = [randilist(1,6,n), randilist(1,6,n), randilist(1,6,n)] # Each of the three lists in D is the record of the N rolls of one of # the three dice. # Hint: assign to a variable m the number of times that EXACTLY two # of the dice have the same value. Page 9

5. [6 points] These classes were involved in Assignment 6: class Speech(object): attributes: thespeaker lines class Scene(object): attributes: actnumber scenenumber location the name of the speaker [str] each item is a (file) line in the speech [list of str] the number of the act [int] the number of the scene [int] the location of the scene [str] class Play(object): attributes: thetitle thespeeches thescenes nlines the name of the play [str] a list of all the speeches in the play [list(speech)] a list of all the scenes in the play [list(scene)] the total number of lines in the play [int] Complete the following function so that it performs as specified. Hint: you don t need stringtowordlist. def qmarks(playlist): Returns the total number of question marks that occur amongst all the lines in all the speeches in all the plays referenced by playlist. PreC: playlist is a list of references to Play objects. 6. [1 point] Write your last name, first name, and Cornell NetID at the top of each page, and circle your lab time on the first page. We suggest you carefully re-read all instructions and specifications before turning this exam in. Page 10