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

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

CS 115 Exam 1, Fall 2015 Thu. 09/24/2015

CS 115 Exam 3, Spring 2014

CS 115 Exam 3, Fall 2016, Sections 1-4

CS 115 Exam 3, Fall 2016, Sections 5-8

CS 115 Exam 3, Spring 2015, Sections 1-4

CS 115 Exam 3, Fall 2011

CS 115 Exam 3, Fall 2015, Sections 1-4

Midterm I - Solution CS164, Spring 2014

CS150 Sample Final. Name: Section: A / B

Practical Questions CSCA48 Week 6

CS150 - Sample Final

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

Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1

CS 115 Exam 3, Spring 2011

CS 351 Exam 3, Fall 2011

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

Control Flow: Loop Statements

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

CSE 160 Winter 2016: Final Exam

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

CS150 Sample Final Solution

CS 450 Exam 2 Mon. 4/11/2016

Spring 2017 CS 1110/1111 Exam 1

CSE 160 Winter 2016: Final Exam

CS 351 Exam 3 Mon. 5/11/2015

Q1: Multiple choice / 20 Q2: Arrays / 40 Q3: Functions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

22C:16 CS:1210 Exam 2

Final Exam Version A

THE AUSTRALIAN NATIONAL UNIVERSITY Mid Semester Examination September COMP1730 / COMP6730 Programming for Scientists

CS 373: Combinatorial Algorithms, Spring 1999

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

Short Answer Questions (40 points)

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

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

CSCI 101 Midterm Sample Questions

CS 1110 Prelim 2 November 6th, 2012

First Midterm Exam CS164, Fall 2007 Oct 2, 2007

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

Spring 2017 CS 1110/1111 Exam 2

Structure and Interpretation of Computer Programs Spring 2019 Midterm 2

ENGR 102 Engineering Lab I - Computation

CS 351 Exam 1, Fall 2010

CS 2316 Exam 1 Practice ANSWER KEY

15-110: Principles of Computing Sample Exam #1

File Operations. Working with files in Python. Files are persistent data storage. File Extensions. CS111 Computer Programming

COP 3223 Introduction to Programming with C - Study Union - Spring 2018

Structure and Interpretation of Computer Programs

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

File Operations. Working with files in Python. Files are persistent data storage. File Extensions. CS111 Computer Programming

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

Text University of Bolton.

CS 450 Exam 2 Mon. 11/7/2016

Module 3: Strings and Input/Output

CS Exam 2 Name: Your Grading TA: This exam has 7 pages including the title page. Please check to make sure all pages are included.

CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have

CS 1110 Prelim 2 April 22, 2014

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

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

CS 1110 Prelim 2 April 26th, 2016

CS 351 Exam 3, Fall 2013

CS 1110 Prelim 1 October 17th, 2013

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

CS 1301 Exam 1 Spring 2014

Standard stuff. Class webpage: cs.rhodes.edu/db Textbook: get it somewhere; used is fine. Prerequisite: CS 241 Coursework:

1 Fall 2017 CS 1110/1111 Exam 3

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

CSc 110 Sample Final Exam #1

Midterm I (Solutions) CS164, Spring 2002

Name: id: Pledge: Notices. Test rules. Page 1 of 7. CS 1112 Spring 2018 Test 3

CS 1110 Prelim 1 March 15th, 2016

UNIVERSITY OF TORONTO SCARBOROUGH. Wnter 2016 EXAMINATIONS. CSC A20H Duration 2 hours 45 mins. No Aids Allowed

Read this before starting!

CSE143 Midterm Summer Name of Student: Section (e.g., AA): Student Number:

EECE.2160: ECE Application Programming Spring 2016 Exam 1 Solution

Flow Control: Branches and loops

Structure and Interpretation of Computer Programs

CS100 Spring 2017 Final

CSc 110 Sample Midterm Exam #2

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

Structure and Interpretation of Computer Programs

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

CS 1301 Exam 1 Fall 2010

CS 351 Exam 2, Fall 2012

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

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

Structure and Interpretation of Computer Programs

Mathematics Masters Examination

CS 1110 Prelim 1 October 4th, 2012

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

6.189 Exam Friday, January 11

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

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

Write code that simulates one roll of a 6-sided die and prints out the

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

Structure and Interpretation of Computer Programs

Loops and Conditionals. HORT Lecture 11 Instructor: Kranthi Varala

CS 1110 Prelim 2 November 13th, 2014

ECE264 Fall 2013 Exam 1, September 24, 2013

Chapter 2 Input, Processing and Output. Hong Sun COSC 1436 Spring 2017 Jan 30, 2017

Transcription:

CS 115 Exam 2 (Section 1) Spring 2017 Thu. 03/31/2017 Name: Rules and Hints You may use one handwritten 8.5 x 11 cheat sheet (front and back). This is the only additional resource you may consult during this exam. No calculators. When you write code, be sure that the indentation level of each statement is clear. Explain/show work if you want to receive partial credit for wrong answers. As long as your code is correct, you will get full credit. No points for style. As always, the SSU rules on academic integrity are in effect. Problem Max Score Your Score Problem 1: Trace Code 20 Problem 2: Trace Functions 20 Problem 3: Define functions 30 Problem 4: Write a complete program 30 Total 100 Page 1 of 11

CS115 Exam 2 Page 2 of 11 Problem 1: Trace Code (20 points) Write what will be printed to the screen when each of the following snippets of code is executed in PyCharm or in the Online Python Tutor. Write your final solution in the box provided Do not write any scratch-work in the solution box. In your solution, be very precise with spacing, line breaks, etc. Treat each sub-problem as an independent question. All questions in this section are worth 4 points. Problem 1A x = 1 y = 6 while x < y: x = x+2 print (x, y) Problem 1B s = ' Go Seawolves!' print ( len (s)) print (s[ len (s) -1]) print (s [:5]) print (s [ -7: -1])

CS115 Exam 2 Page 3 of 11 Problem 1C s = ['lion ', 'tiger ', 'bear ', 'oh ', 'my '] print ( len (s)) print (s [2]) print ( len (s [2])) print (s [2][1]) Problem 1D A = [0,2,4,6,8] B = A C = A [:] B [0] = sum (A) C [2] = sum (A) print (B) print (C) Problem 1E L = [1,2,3] try : print ('L =', L) L = L [: -1] + 4 print ('L =', L) except Exception as e: print (' error :', L)

CS115 Exam 2 Page 4 of 11 Problem 2: Trace Functions (20 points) Write what will be printed to the screen when each of the following snippets of code is executed in PyCharm or in the Online Python Tutor. Write your solution in the box provided. Do not write any scratch-work in the solution box. In your solution, be very precise with spacing, line breaks, etc. Treat each sub-problem as an independent question. All questions in this section are worth 5 points. Problem 2A def cat (a,b): return a+b a = 'xxx ' b = 'yyy ' z = cat (b,a) print (z) Problem 2B def mystery ( str ): s = '' for c in str : s = c + s + c return s str = mystery (' ba ') print ( str )

CS115 Exam 2 Page 5 of 11 Problem 2C def combinefirstlast ( A): return A [0] + A[ -1] A = [[1], [2,3], [4,5,6]] L = combinefirstlast ( A) print ( len (A), len (L), L) Problem 2D def subl (L): for i in range ( len (L )): L[i] = L[i] - L [0] A = [1,2,3] subl (A) print (A)

CS115 Exam 2 Page 6 of 11 Problem 3: Define functions (30 points) Define functions to perform the following tasks, obeying the stated requirements, including: Assume that the math library has been imported for you. Do not ask the user for input unless the specification explicitly requires it. Do not print anything unless the specification explicitly requires it. Do not call any function unless unless the specification explicitly requires it. Problem 3A (10 points) Write a function named area that enables this code: print (" Triangle with b", 10, " and h", 20, " has area ", 10*20/2) print (" Triangle with b", 15, " and h", 11, " has area ", 15*11/2) print (" Triangle with b", 7, " and h", 5, " has area ", 7*5/2) to be replaced with the following code: area (10,20) area (15,11) area (7,5)

CS115 Exam 2 Page 7 of 11 Problem 3B (10 points) Define a function named word_reverse that: Takes 1 parameter: a string Returns a string with the words in reverse order Example of calling this function: word_reverse("the quick brown fox") returns "fox brown quick The"

CS115 Exam 2 Page 8 of 11 Problem 3C (10 points) Define a function named getrowsum that: Takes 2 parameters: a nested (2-dimensional) list and an integer j Returns the sum of all elements in row j You can assume that row j exists. Example of calling this function: Let L = [[5,10,15], [1,2,3], [7,8,9]], then getrowsum(l,0) returns 30

CS115 Exam 2 Page 9 of 11 Problem 4: Write a complete program (30 points) For this problem, you must write a complete program. This includes writing a docstring, logic in def main(), a call to main(), any necessary library imports, etc. Read the instructions carefully before you start coding! If you get stuck, try to maximize your partial credit. To get full credit, your functions should call each other where appropriate and avoid duplicating code. In all examples, user input is underlined. Your program should contain the following functions: get_names: Takes no parameters. Prompts the user for names until the user enters a blank line. Each line of user input should be considered a name. Returns a list of the names the user entered (not including the blank line). Example: A call to get_names with the below sample user input Enter a name : Harry James Potter Enter a name : Hermione Jean Granger Enter a name : should return the list ['Harry James Potter', 'Hermione Jean Granger']. make_initials: Takes a string as a parameter and returns a string that holds its initials (the first letter from each word in the original string, in upper case). Example: Given 'harry james Potter', the function returns 'HJP'. main: Calls get_names to get a list of names from the user. For each name in the list, creates the initials by calling make_initials and prints the name and initials for it. Given the sample inputs below, your program should match the sample output exactly. Sample input/output: Enter a name : Harry James Potter Enter a name : Hermione Granger Enter a name : Ronald Bilius weasley Enter a name : Harry James Potter ( HJP ) Hermione Granger ( HG) Ronald Bilius weasley ( RBW ) Start your solution on the next page...

CS115 Exam 2 Page 10 of 11 Problem 4, continued...

CS115 Exam 2 Page 11 of 11 Problem 4, continued...