CS 1110 Prelim 1 March 10, 2015

Similar documents
CS 1110 Prelim 2 April 21, 2015

CS 1110 Prelim 1 March 15th, 2016

CS 1110 Prelim 2 April 26th, 2016

CS 1110 Prelim 2 April 22, 2014

CS 1110 Regular Prelim 1, March 14th, 2017

CS 1110 Prelim 1, March 2018

CS 4620 Midterm, March 21, 2017

CS 1110 Prelim 1 March 7th, 2013

Assignment 4: Due Friday Mar 11 at 6pm

CS 1110 Prelim 1 October 17th, 2013

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

CS 1110 Final Exam, May 2018

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

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

5. Introduction to Procedures

CS 1110 Prelim 1 October 4th, 2012

CS 1110 Final, May 2017

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

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

CS 1110 SPRING 2016: LAB 3: PRACTICE FOR A2 (Feb 23-24)

CS 1110 Final Exam May 9th, 2013 SOLUTIONS

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

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

CS1110 Lab 6 (Mar 17-18, 2015)

CS 1301 Exam 1 Fall 2010

Lecture 11. Asserts and Error Handling

CS 1110 Prelim 1 October 15th, 2015

CS 1110 Prelim 2 November 6th, 2012

CS 1110 Prelim 1 October 12th, 2017

CS 1110 Prelim 2 November 14th, 2013

CSC A20H3 S 2011 Test 1 Duration 90 minutes Aids allowed: none. Student Number:

Spring 2017 CS 1110/1111 Exam 1

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

CS 1110 Prelim 2 November 13th, 2014

CS 1301 Exam 1 Fall 2014

CS 1301 Exam 1 Fall 2010

Lecture 8: Conditionals & Control Flow (Sections ) CS 1110 Introduction to Computing Using Python

CS 1301 Exam 1 Fall 2014

CS 1110 Prelim 2 November 12th, 2015

Assignment 2: Due Friday Feb 13 at 6pm

Page 1 of 7 E7 Spring 2009 Midterm I SID: UNIVERSITY OF CALIFORNIA, BERKELEY Department of Civil and Environmental Engineering. Practice Midterm 01

Midterm Exam 2A Principles of Computing Fall November 10, 2014

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

Prelim 2. CS 2110, April 26, 2016, 5:30 PM Total Question True/False Complexity Heaps Trees Graphs Max Score Grader

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

Lecture 11. Asserts and Error Handling

Prelim 1. CS 2110, March 15, 2016, 5:30 PM Total Question Name True False. Short Answer

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

Prelim 2 Solution. CS 2110, April 26, 2016, 5:30 PM

Prelim 1. CS 2110, 13 March 2018, 7:30 PM Total Question Name Short answer

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

15-110: Principles of Computing, Spring 2018

Prelim 1, Solution. CS 2110, 13 March 2018, 7:30 PM Total Question Name Short answer

Prelim 1. CS 2110, 13 March 2018, 5:30 PM Total Question Name Short answer

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

CMPSCI 119 Fall 2018 Wednesday, November 14, 2018 Midterm #2 Solution Key Professor William T. Verts

3. Conditional Execution

Spring 2017 CS 1110/1111 Exam 2

CS 1110 Prelim 2 November 10th, 2016

CS 115 Lecture 8. Selection: the if statement. Neil Moore

Prelim 1. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer. OO Recursion Loop invariants Max Score Grader

15-110: Principles of Computing, Spring Problem Set 3 (PS3) Due: Friday, February 9 by 2:30PM on Gradescope

CSE 131 Introduction to Computer Science Fall Exam II

Read this before starting!

C ONTROL AND H IGHER O RDER F UNCTIONS

EXAMINATION INSTRUCTIONS

Read this before starting!

CS Lecture 19: Loop invariants

Prelim 1. CS 2110, March 15, 2016, 7:30 PM Total Question Name True False. Short Answer

CS 1110 Final, December 16th, 2013

CSE 131S Introduction to Computer Science Summer SON Exam I

CSE 130, Winter 2011: Final Examination

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CPSC 217 L01 Midterm

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

Introduction to Java Applications

Midterm Exam 2B Answer key

Prelim 2, CS :30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs

Conditionals & Control Flow

Lecture 19. Using Classes Effectively

CS 122/132 Midterm Exam Winter 2003

CSCE 110: Programming I

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

3. Conditional Execution

York University Faculty Science and Engineering Fall 2008

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Overview of List Syntax

CS 1110 Final, December 7th, 2017

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

Iteration and For Loops

CSE 131 Introduction to Computer Science Fall Exam I

CS 1301 Exam 1 Fall 2013

CS 1301 Exam 1 Spring 2011

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

4. Modules and Functions

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CS 1110 Final, December 16th, 2013

(c) ((!(a && b)) == (!a!b)) TRUE / FALSE. (f) ((!(a b)) == (!a &&!b)) TRUE / FALSE. (g) (!(!a) && (c-d > 0) && (b!b))

Types, lists & functions

Transcription:

CS 1110 Prelim 1 March 10, 2015 (Print Last Name) (Print First Name) (Net ID) Circle Your Lab: 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 Write your name and NetID on every page. Check that your exam has (11) pages counting this one. In cases where you write code, you will lose points for ambiguous indentation. Academic Integrity 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)

Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Problem 6 15 points 20 points 20 points 15 points 20 points 10 points

1 String Manipulation (a) Implement the following function so that it performs as specified. def Q1(s): """ Returns True if the characters at the start and end of s are the same and occur nowhere else in s PreCondition: s is a string with length greater than or equal to 3. """ (b) Imagine playing around with this script: s = raw_input( Enter a string that has length greater than or equal to 2: ) t = s.replace(s[0], x ) u = t.replace( x,s[0]) print s,u Sometimes it is the case that the printed values of s and u are the same and sometimes it is observed that they are different. Give a Boolean expression that is True if u and s have the same value and is False otherwise. Hint. Consider some small examples.

2 Random Walk Consider the random walk simulation in Assignment 4. Recall that the simulation produces a travel string comprised of the characters N, S, E, and W. The travel string encodes the hop directions associated with the robots journey from (0,0) to a purple boundary tile. Here is a display of an n = 5 playpen highlighting its four middle edge tiles: (a) Assume that x and y are initialized with the (x, y) coordinates of the robot s location and that the value of n is the size of the playpen. Give a Boolean expression that is True if the robot is on a middle edge tile and False otherwise. (b) A hop is predictable if it is in the same direction as the previous hop. Here is a travel string that includes 3 predictable hops: EWNNNWWN. Complete the following function so that it performs as specified. def npredictable(s): """ Returns an int that is the number of predictable hops in s. Precondition: s is a travel string. """

(c) Assume that s is initialized and contains a travel string. xf is initialized and contains the x-coordinate of the robot s final location. yf is initialized and contains the y-coordinate of the robot s final location. Write Python code that assigns to variables x and y the x-coordinate and y-coordinate of the last yellow tile on the robot s journey. Points will be deducted for solutions that involve a loop.

3 Short Answer (a) Assign a value to x so that the character A is printed out: x = if x%2==0 and x%3==1: print A (b) Assign values to x and y so that the character D is printed out: x = y = if not ((0<=x<=3) and (0<=y<=3)): print A elif y<=1 or y>=2: print B elif x<=1 or x>=2: print C else: print D (c) What would be the output if the following code is executed? x = float(10/4) print x

(d) Suppose the functions in modules M1.py and M2.py are to be used by module M.py. Briefly explain why it is safer to implement M.py with than with import M1 import M2 from M1 import * from M2 import * (e) Indicate what the output would be if the following application script is run: def F(x,y): x = y y = x z = x+2*y print x,y,z return z if name == main : x = 1 y = 2 print x,y x = F(y,x) print x,y if x<y: print A else: print B

4 Testing In the You Are Late problem in assignment A1 you essentially implemented the following function: def YouAreLate(s): """ Returns a time string that specifies a time that is 90 minutes earlier than the time specified by s. A time string has these properties: (a) its length is 5 (b) its middle character is : (c) its first two characters are 01, 02,..., 09, 10, 11, or 12 (d) its last two characters are 00, 01,..., 58, or 59 Precondition: s is a time string """ In assignment A2 you assembled 10 representative test cases that could be used to help affirm the correctness of your WindChill implementation. This problem is about applying the representative test idea to the function YouAreLate. In particular, complete the following table so that it specifies a collection of six representative test cases that could be used to check the correctness of a YouAreLate implementation. Test Case Expected Output What it Checks 01:15 11:45 Points will be deducted for test cases that do not contribute any new information about correctness when compared to the other test cases. Test cases that check for valid input will not add to your score on this problem. To enforce brevity, we will not consider anything written outside of the table.

5 Loops (a) Consider the following script t = x s = raw_input( Enter a string: ) for c in s: t = t + c + t Assuming that ba is assigned to s, what is the final value of t? Show work. (b) Write a script that is equivalent to the script in part (a) but which uses a while-loop instead of a for-loop.

6 A Graphics Procedure Assume the availability of the following procedure: def DrawRow(x0,y0,s,n): """ Draws a horizontal row of n squares that are each s-by-s. The center of the leftmost square is (x0,y0). Precondition: x0, y0, and s are floats, n is a positive integer""" By making effective use of DrawRow, implement the following procedure so that it performs as specified def DrawPyramid(x0,y0,s,n): """ Draws a pyramid of s-by-s squares. The bottom row consists of n squares and the lower left corner of the leftmost square is at (x0,y0). There are n rows of squares and each row has one less square than the row beneath it. The centers of each row are vertically aligned. Precondition: x0, y0, and s are floats, n is a positive integer""" For your information, the call DrawPyramid(-5.,-5.,2.,5) would produce this figure:

Function Information len(s) Function returns an int that is the length of string s What It Does s.count(t) s.find(t) returns an int that is the number of occurrences of string t in string s returns an int that is the index of the first occurrence of string t in the string s. Returns -1 if no occurrence. s.replace(t1,t2) returns a string that is obtained from s by replacing all occurrences of t1 with t2. floor(x) returns a float whose value is the largest integer less than or equal to the value of x. ceil(x) int(x) float(x) str(x) returns a float whose value is the smallest integer greater than or equal to the value of x If x has type float, converts its value into an int. If x is a string like -123, converts it into an int like -123 If x has type int, converts its value into a float. If x is a string like 1.23, converts it into a float like 1.23. Converts the value of x into a string. DrawRect(x,y,L,W) Draws a rectangle with center (x, y), horizontal dimension L, and vertical dimension W. DrawDisk(x,y,r) Draws a circle with center (x, y) and radius r. DrawStar(x,y,r) Draws a star with center (x, y) and radius r. DrawLineSeg(x,y,L,d) Draws a length L line segment that starts at (x,y) and makes counterclockwise angle of d degrees with the positive x-axis.