Final Exam Version A

Similar documents
Sample Final Exam Questions

Version B Final Exam

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

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

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

CS 1301 Exam 1 Fall 2010

COMP519 Web Programming Lecture 20: Python (Part 4) Handouts

CSE : Python Programming. Homework 5 and Projects. Announcements. Course project: Overview. Course Project: Grading criteria

Structure and Interpretation of Computer Programs

Review 3. Exceptions and Try-Except Blocks

Problem Score Max Score 1 Syntax directed translation & type

Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1

Lecture #15: Generic Functions and Expressivity. Last modified: Wed Mar 1 15:51: CS61A: Lecture #16 1

Introduction to: Computers & Programming: Exception Handling

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

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

CS 1301 Exam 1 Fall 2010

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

CS 115 Exam 2 (Section 1) Fall 2017 Thu. 11/09/2017

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

Structure and Interpretation of Computer Programs

CS100 Spring 2017 Final

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

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

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

Question: Total Points: Score:

Exception Handling. Genome 559

CS 111X - Spring Final Exam - KEY

Structure and Interpretation of Computer Programs

Lecture 21. Programming with Subclasses

Exceptions & a Taste of Declarative Programming in SQL

Midterm #2a Spring minutes

More Functions. CS 1111 Introduction to Programming. Spring 2019

CS 1110, LAB 3: MODULES AND TESTING First Name: Last Name: NetID:

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

Structure and Interpretation of Computer Programs

All program statements you write should be syntactically correct. Partial credit is not guaranteed with incorrect use of syntax.

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

22C:16 CS:1210 Exam 2

Chapter 9: Dealing with Errors

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

CS 11 python track: lecture 2

Abstract Data Types Chapter 1

Structure and Interpretation of Computer Programs Summer 2015 Midterm 2

CS 100 Spring 2016 Midterm 1

Structure and Interpretation of Computer Programs

Lecture #12: Quick: Exceptions and SQL

CS150 Sample Final. Name: Section: A / B

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

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

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

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

CSCE 110: Programming I

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

CS 115 Exam 3, Spring 2014

Lecture 21. Programming with Subclasses

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

Spring 2017 CS 1110/1111 Exam 2

CS 111X - Fall Test 1

LECTURE 4 Python Basics Part 3

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

Lecture 17: Classes (Chapter 15)

Structure and Interpretation of Computer Programs

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

CSE341 Autumn 2017, Midterm Examination October 30, 2017

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

FORM 2 (Please put your name and form # on the scantron!!!!)

Spring 2017 CS 1110/1111 Exam 3

Structure and Interpretation of Computer Programs Summer 2014 Midterm 1

CS 201 Exam 3 Spring 2005 Grading Key

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

CS Lecture 26: Grab Bag. Announcements

CS143 Final Fall 2009

: Intro Programming for Scientists and Engineers Final Exam

CS 1110 Prelim 1 October 15th, 2015

CIS192 Python Programming

CIS192 Python Programming

Question 1. tmp = Stack() # Transfer every item from stk onto tmp. while not stk.is_empty(): tmp.push(stk.pop())

Structure and Interpretation of Computer Programs

University of Washington CSE 140 Introduction to Data Programming Winter Midterm exam. February 6, 2013

Structure and Interpretation of Computer Programs Fall 2015 Midterm 1

Python Essential Reference, Second Edition - Chapter 5: Control Flow Page 1 of 8

Final Exam CS 152, Computer Programming Fundamentals May 9, 2014

7. (2 pts) str( str( b ) ) str '4' will not compile (single, double, or triple quotes

Structure and Interpretation of Computer Programs

Final Exam CS 251, Intermediate Programming December 10, 2014

CS Programming Languages: Python

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

Structure and Interpretation of Computer Programs

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

CS1150 Principles of Computer Science Methods

Structure and Interpretation of Computer Programs Spring 2019 Midterm 2

1 Classes. 2 Exceptions. 3 Using Other Code. 4 Problems. Sandeep Sadanandan (TU, Munich) Python For Fine Programmers May 16, / 19

Structure and Interpretation of Computer Programs

CS 1301 Exam 1 Fall 2014

Structure and Interpretation of Computer Programs

CS150 Sample Final Solution

Structure and Interpretation of Computer Programs Summer 2015 Midterm 1

CIS192 Python Programming

EXPRESSIONS, STATEMENTS, AND FUNCTIONS 1

Transcription:

CS112 Spring 2014 Dr. Kinga Dobolyi Final Exam Version A Do not open this exam until you are told. Read these instructions: 1. This is a closed book exam. No calculators, notes, or other aids are allowed. If you have a question during the exam, please come to the front of the class. 2. You must turn in your exam immediately when time is called at the end. 3. The exams adds up to 45 points total. 120 minutes. Each question s point value is indicated. 4. In order to be eligible for as much partial credit as possible, show all of your work for each problem, write legibly, and clearly indicate your answers. Credit cannot be given for illegible answers. 7. Fill in the following: NAME : G# : (write your name and G# on your scantron also) DO NOT OPEN UNTIL TOLD TO START But ask me about my hint for returns!

A. Trace through the following code using the scratch space below, and then write your answer in the box on the right- hand side. Then, TRANSFER YOUR ANSWER to the scantron sheet line- by- line. print ERROR if the line would have raised an exception. (10 points) def func1(x,y,lis): print lis[y:x] lis[x] = lis[y] lis = [x] return lis def func2(a,b,nums): print a in nums.keys() print nums[b] nums[1] = 2 def main(x): x = x + 1 lis = [4,6,8,9,10] things = [7,lis,x] lis = func1(x,2,lis) print lis print things if x == 3: dict = {x:x,1:lis,"c":"dog"} print func2('x',0,dict) print dict[1] main(2) main(1) WILL NOT BE GRADED! COPY TO SCANTRON! A1 A2 A3 A4 A5 A6 A7 A8 A9 A10

B. Trace through the following code using the scratch space below, and then write your answer in the box on the right- hand side. Then, TRANSFER YOUR ANSWER to the scantron WILL NOT BE GRADED! sheet line- by- line. (9 points) COPY TO SCANTRON! def func1(x,lis): print "lis[x]: " + lis[x] if x > 0: x -= 1 else: x += 6 try: integer = int(lis[x]) print "div: " + str(5//integer) print "all good" except TypeError: print "incompatible types!" except ZeroDivisionError: print "div by zero!" raise ValueError() else: print "func1" return "done func1" def main(x): try: print func1(x,["c",2,"1","0","7"]) print "success" except TypeError: print "wrong" except Exception: print "oops" main(2) main(0) main(1) main(4) B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 B12

Multiple choice. 1. What is the correct method signature, defined in person.py, of the constructor for a class called Person, which can be called as p = Person( Sally,23)? a. def Person(self, name, age): b. def init (self, name, age): c. def init (self, name, age, zip): d. a and b e. b and c 2. Imagine I wrote a Person class with a constructor that sets an attribute called name to the value of an incoming argument. What is wrong with the following method of the same class, defined in the appropriate place in the same module, that wants to set the name attribute to another incoming argument? def foo(self, newname): name = newname a. name cannot be reset after it was initialized b. foo can be called without ever creating an object c. The method has no effect on the attribute name of the object d. Nothing; what is written above is correct 3. If the constructor for a class called Person can only be called with two arguments (no less, no more), what must be true about the attributes of a Person object? a. A Person object can only have at most two attributes b. A Person object can have more than two attributes c. The Person constructor takes a third argument with a default value 4. The statement from project2 import * imports all the functions in the file project2.py into the file where this statement was written a. True b. False 5. In a try- except block, the finally clause is not executed if an exception was raised in the matching try block. a. True b. False 6. If you try to open a file for reading in python, and it doesn t exist, you will receive an error message a. True b. False 7. If lis1 = [4, 7, 1] and lis2 = [8,2,0], what does lis2[lis1[2]] evaluate to? a. 1 b. 4 c. 2 d. ERROR

8. range(len([8,9])) simplifies to which of the following? a. [ ] b. [0, 1] c. [1, 2] d. ERROR CHOOSE ONE of the following two problems to answer. You DO NOT have to answer both; pick the one you find more to your liking. If you attempt both problems, I WILL ONLY GRADE ONE OF THEM. If you attempt both problems, I will grade the first one. If you want to initially attempt both problems, make it clear to me which one you want to be counted, otherwise I will only grade the first one.

Option 1: Write a function called scan that takes a string as an argument and prints out one, and only one, of the following according to the argument: ME if the string me is in the input at least once OM if the string om is in the input at least once MEH if the string meh is in the input at least once OVERLAP if more than one of the previous three bullets are true NONE if none of the previous bullets are true You may NOT use any built- in functions or methods besides len, and you may NOT use the in keyword.

Option 2: Write a function called sumeven that accepts a list of strings as its argument. Each string will be either an integer, or the @ character. The function will return a list of sums of even integers between @ signs. It will ignore every third element in the list, regardless of that element s contents. The incoming list is guaranteed to have an even number before an @ sign. For example, sumeven(['2']) would return the list [2] sumeven(['1']) would return the list [0] sumeven(['2','@','5']) would return the list [2, 0] sumeven[ 2, 3, @, 4, 1, 6, @, 3, 2, @, 2, 2, 1, 2 ] would return the list [6, 0, 4] You may NOT use any built- in functions or methods besides int, len and append.

Scratch paper rip off and turn in

Name: