Spring 2017 CS 1110/1111 Exam 3

Similar documents
Spring 2017 CS 1110/1111 Exam 1

Spring 2017 CS 1110/1111 Exam 2

(the bubble footer is automatically inserted into this space)

1 Fall 2017 CS 1110/1111 Exam 3

CS 1301 Exam 1 Fall 2010

CS 1301 Exam 1 Fall 2010

Short Answer Questions (40 points)

CS 111X - Spring Final Exam - KEY

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

CSE 131 Introduction to Computer Science Fall Exam I

CS 111X - Fall Test 1

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

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

CSE 131 Introduction to Computer Science Fall Exam I

Decision Logic: if, if else, switch, Boolean conditions and variables

(the bubble footer is automatically inserted in this space)

CSE 131 Introduction to Computer Science Fall Exam II

CSE 247 Data Structures and Algorithms Fall Exam I

ASSIGNMENT 3. COMP-202, Winter 2015, All Sections. Due: Tuesday, February 24, 2015 (23:59)

CS 1301 Exam 1 Spring 2011

: Intro Programming for Scientists and Engineers Final Exam

(the bubble footer is automatically inserted into this space)

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

CS 2316 Exam 4 Fall 2011

(the bubble footer is automatically inserted into this space)

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

All written answers are limited to their question boxes. Make sure all answers are easily legible.

CS143 Final Spring 2016

CS 1301 Exam 3 Fall 2010

Structure and Interpretation of Computer Programs

CSCI 150 Exam 2 Solutions

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

def F a c t o r i a l ( n ) : i f n == 1 : return 1 else : return n F a c t o r i a l ( n 1) def main ( ) : print ( F a c t o r i a l ( 4 ) )

Functions. Def. Let A and B be sets. A function f from A to B is an assignment of exactly one element of B to each element of A.

This homework has an opportunity for substantial extra credit, which is described at the end of this document.

Control Flow: Loop Statements

Structure and Interpretation of Computer Programs

CS 2316 Exam 1 Spring 2013

CS 1803 Fall 2010 Exam 1

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

CS 1301 Exam 1 Spring 2014

CSE au Final Exam Sample Solution

Structure and Interpretation of Computer Programs

Final Exam Version A

CS 1301 Exam 2 Fall 2010

CS 1803 Fall 2010 Exam 1

Notices. Test rules. Page 1 of 8. CS 1112 Spring 2018 Test 2

CS 2316 Exam 4 Fall 2011

Your (printed!) Name: CS 1803 Exam 3. Grading TA / Section: Monday, Nov. 22th, 2010

CSE 131S Introduction to Computer Science Summer SON Exam I

(the bubble footer is automatically inserted into this space)

CS 1301 Exam 1 Fall 2013

CS 3L (Clancy) Solutions and grading standards for exam 1

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

(the bubble footer is automatically inserted in this space)

CS 2150 Final Exam, Spring 2018 Page 1 of 10 UVa userid:

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

CS 2316 Exam 1 Spring 2014

Structure and Interpretation of Computer Programs

CS 1301 Exam 3 Fall 2014

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

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

CSCE 110: Programming I

Structure and Interpretation of Computer Programs

CS 3330 Exam 2 Spring 2016 Name: EXAM KEY Computing ID: KEY

CS3330 Exam 1 Spring Name: CS3330 Spring 2015 Exam 1 Page 1 of 6 ID: KEY

COS 126 General Computer Science Spring Written Exam 1

CS 2316 Exam 3 Fall 2011

CS 301: Recursion. The Art of Self Reference. Tyler Caraza-Harter

CS 2316 Exam 4 Spring 2013

3. Determine whether f is a function from the set of all bit strings to the set of integers if

Final Exam. COMP Summer I June 26, points

Spring 2018 PhD Qualifying Exam in Languages

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

The syntax and semantics of Beginning Student

The syntax and semantics of Beginning Student

Section 004 Spring CS 170 Exam 1. Name (print): Instructions:

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

CS 201 Exam 3 Spring 2005 Grading Key

(the bubble footer is automatically inserted in this space)

Structure and Interpretation of Computer Programs Spring 2016 Test 1

CS1150 Principles of Computer Science Methods

Computer Science E-119 Fall Problem Set 1. Due before lecture on Wednesday, September 26

CS 2316 Exam 3 Fall 2012

Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1

CS150 Sample Final. Name: Section: A / B

CS 1301 Exam 1 Spring 2014

Common Loop Algorithms 9/21/16 42

Programming Assignment 2

CS 1301 Exam 3 Spring 2014

Do not start the test until instructed to do so!

Test 1: CPS 100. Owen Astrachan. October 1, 2004

CS 1301 Exam 1 Fall 2013

UNIVERSITY OF TORONTO SCARBOROUGH. Fall 2015 EXAMINATIONS. CSC A20H Duration 3 hours. No Aids Allowed

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

Midterm I Practice Problems

Q1 Q2 Q3 Q4 Q5 Total 1 * 7 1 * 5 20 * * Final marks Marks First Question

CS150 Sample Final Solution

Midterm #1 Fall minutes

You must bring your ID to the exam.

Transcription:

Spring 2017 CS 1110/1111 Exam 3 Bubble in your computing ID, top to bottom, in the footer of this page. We use an optical scanner to read it, so fill in the bubbles darkly. If you have a shorter ID, leave some rows blank. In case we have trouble with the scanner, please also legibly print Your name: Your computing ID: Please observe the following directions throughout the exam: Write legibly; we deduct points if we are unsure what you wrote. Indentation and punctuation do matter. Write on the lines, where possible. If you need to insert a line between two you ve written, make it clear that that is what you are doing. We grade one page at a time. Do not spill answers onto another page. Don t add features we didn t request: only print if we ask you to print, etc. The exam is being given in multiple locations simultaneously, so we cannot fairly answer student questions during the exam. If you find a question ambiguous or unclear, write that down on your exam and we ll give it due consideration during grading. Pledge On my honor as a student, I have neither given nor received help or assistance on this exam. Signed:

Question 1 (10 points) When the following program reaches the line labeled inspect variables here, what is the value and type of each variable? Write Error if the variable does not exist. x, y = 3, '3' def f(z): x = z + 5 print('w =', 7) return z // 2 z = 7.0 * 2 a = f(x) # inspect variables here Variable Value Type x y z w a Question 2 (10 points new question) Write a function named middle that accepts a single string as its argument and returns either the middle character (for an odd-length string) or the middle two characters (for an even-length string) of the string. For example, given "power" return "w" and given "glow" return "lo". Question 3 (4 points) Write a single expression (no more than one line of Python code) on the line below that evaluates to True if either of the following are true and False if neither is true: x is True y and z have different signs (one negative, one positive; you may assume neither is zero) 2

Question 4 (6 points) Assume x = {1:2, 3:4}; y = [5, 6, 7, 8]; and z = range(9, 19). Fill in the following tables. Expression Value Expression Value 2 in x 19 in z z[3] y.index(8) len(y) - len(x) y[x[1]] Question 5 (10 points) Write a program that prompts the user to type integers, one per line, continuing until 0 is typed. Then print a list of the numbers typed, smallest-to-largest, including the 0. You may assume the user only types integers. Example run: Type a number: 3 Type a number: -8 Type a number: 0 [-8, 0, 3] 3

Question 6 (9 points) Give an example invocation that will cause the following function to return the int-value 3. Note: f("2", 1.0, 3) is not a correct answer: it returns "3" not 3. def f(a, b, c): x = a * int(a) if len(x) > 3: try: return float(b) except: return c else: return str(c) Answer: f(,, ) Question 7 (10 points) Write a function stack that accepts three gamebox arguments, a, b, and ground. Remove all overlaps, moving a and b but not ground. To prevent the upper box pushing the lower box into the ground, resolve the overlaps of the lower box first (lower = larger y coordinate). The only gamebox or pygame methods you ll need are box1.touches(box2) box1.move_to_stop_overlapping(box2) which you may abbreviate box1.mso(box2) for brevity box1.move_both_to_stop_overlapping(box2) which you may abbreviate box1.mbso(box2) 4

Question 8 (11 points) Trace through the code below, recording the lines of output, in the order they would appear if you ran the code. We have provided more blank lines than you will need. def foo(x): lis = [5, 6, 7] try: print(x in lis) print(lis[x]) except IndexError: print("bad index") print(x) return 3 try: print(foo(4)) except: print("caught exception") print("done") Prints: Question 9 (9 points) Each row represents one regular expression; each column on string to match with that regular expression. In each cell, enter the number of matches finditer would return. The first row is done for you. "12_13" "Hi_there!" "[1,_2,_[3,_4]]" [a-z] 0 6 0 [A-Z][a-z]* [a-z_]+ ([0-9]+_?)+ ([,_])[,_] Question 10 (11 points) Give three different example strings that match the following regular expression, including at least one that is an English sentence and one that is not. (Teacher Student TA) (of in) [a-z]+( [A-Za-z]+)+\. 5

Question 11 (10 points) Write a function named save_list that takes two arguments: a filename and some data in the form of a list of lists of integers. It should write a CSV file with that name containing those integers; for example, invoking save_list('tmp.csv', [[2, 3], [5, 7, 11], [13]]) should create a file named tmp.csv that contains 2,3 5,7,11 13 You should not include any spaces within each line, but you may end each line with a comma if you wish. def save_list(filename, data): 6