CS 111X - Spring Final Exam - KEY

Similar documents
CS 111X - Fall Test 1

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

Spring 2017 CS 1110/1111 Exam 3

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

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

1 Fall 2017 CS 1110/1111 Exam 3

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

Intro. Scheme Basics. scm> 5 5. scm>

(the bubble footer is automatically inserted into this space)

CS Prelim 2 Review Fall 2018

(the bubble footer is automatically inserted into this space)

CS 1301 Exam 2 Fall 2010

CIS192: Python Programming

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

CS 2316 Exam 1 Spring 2014

CS 1301 Exam 3 Fall 2014

Spring 2017 CS 1110/1111 Exam 2

Structure and Interpretation of Computer Programs

CS 1301 Exam 1 Fall 2010

CS 1803 Fall 2010 Exam 1

CS 1301 Exam 1 Spring 2014

CS 1301 Exam 1 Fall 2014

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

Spring 2017 CS 1110/1111 Exam 1

CS 1301 Exam 1 Fall 2010

CS 1301 Exam 1 Fall 2014

CS 1301 Exam 3 Spring 2012

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

CSCE 206: Structured Programming in C++

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

CS 1301 Exam 1 Spring 2011

COS 126 General Computer Science Spring Written Exam 1

CS Name : Grading TA:

CS 2316 Exam 1 Spring 2013

Multiple Choice Questions (20 questions * 5 points per question = 100 points)

Short Answer Questions (40 points)

Structure and Interpretation of Computer Programs

CS 1301 Exam 3 Spring 2014

CS 2316 Exam 4 Fall 2011

Python review. 1 Python basics. References. CS 234 Naomi Nishimura

CS 1301 Exam 1 Spring 2014

CS Prelim 1 Review Fall 2018

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

CS 2316 Exam 4 Fall 2011

Problem Score Max Score 1 Syntax directed translation & type

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

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

CS 1301 Individual Homework 3 Conditionals & Loops Due: Monday February 8 th before 11:55pm Out of 100 points

EXAMINATION INSTRUCTIONS

Midterm #1 Fall minutes

Final Exam Version A

Midterm I Practice Problems

CS 1301 Exam 3 Fall 2010

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

CPE Summer 2015 Exam I (150 pts) June 18, 2015

University of Michigan EECS 183: Elem. Programming Concepts Fall 2011 Exam 1: Part 1: Form 1. Professors: ML Dorf, Elliot Soloway

Structure and Interpretation of Computer Programs Summer 2014 Midterm 1

Structure and Interpretation of Computer Programs

PRACTICE MIDTERM EXAM #2

CS 142 Style Guide Grading and Details

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

CS 1301 Post Exam 3 Practice Spring 2016

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

CS 1301 Exam 2 A Fall 2015

CSE 131 Introduction to Computer Science Fall Exam I

: Intro Programming for Scientists and Engineers Final Exam

CSE 130, Winter 2011: Final Examination

CS1 Lecture 22 Mar. 6, 2019

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

CS143 Final Fall 2009

CS-141 Exam 2 Review November 10, 2017 Presented by the RIT Computer Science Community

Structure and Interpretation of Computer Programs

CS 1301 Exam 3 A Spring 2015

CS140 Operating Systems and Systems Programming

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

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1

I. True/False: (2 points each)

Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function

CSE 131 Introduction to Computer Science Fall Exam I

Do not start the test until instructed to do so!

CIS192 Python Programming. Robert Rand. August 27, 2015

CS 455 Final Exam Spring 2017 [Bono] May 10, 2017

Final Examination May

CSE 131 Introduction to Computer Science Fall Final Exam

CIS 110 Introduction to Computer Programming Summer 2018 Midterm. Recitation ROOM :

CS 201 Exam 3 Spring 2005 Grading Key

CSC148 Recipe for Designing Classes

Question: Total Points: Score:

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

Practice Midterm 1. Problem Points Score TOTAL 50

CS 1110 Final Exam, May 2018

Structure and Interpretation of Computer Programs

CS 100 Spring 2016 Midterm 1

CSE 131S Introduction to Computer Science Summer SON Exam I

Fall 2002 Page 1 of 9 READ THIS NOW!

Structure and Interpretation of Computer Programs Spring 2019 Midterm 2

Exam Percentage: / 55 = %

Final Examination CS 4501 Spring 2012

On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

Transcription:

CS 111X - Spring 2016 - Final Exam 1/10 Computing ID: CS 111X - Spring 2016 - Final Exam - KEY Name: Computing ID: On my honor as a student, I have neither given nor received unauthorized assistance on this exam. Signature: First, write your name and ID, pledge this test, and bubble your ID on this page. Failure to do so will result in penalty points. This is a closed note, closed book, closed computing device, 3-hour test. You are not to speak with anyone except the instructor or TA for any reason except an emergency during the test. Important: Students may take this test at different times. It is a violation of the Honor Code to talk about the test in any way with a student who has not yet taken it. All questions MUST be answered only on the page on which they are asked (answers on scratch paper or on other pages will not be accepted). Also, hard questions may be mixed with easy questions. If you start a question and it s hard or time-consuming, you might want to save it for the end of the test and go ahead and work on easier problems. State any additional assumptions you make. Good luck!

CS 111X - Spring 2016 - Final Exam 2/10 Computing ID: Multiple Choice [30 pts total; 2 pts each] Question 1. The function removes all whitespace from both ends of a string. A. rstrip() D. concat() B. trim() E. strip() C. remove_whitespace() 2. After the execution of the following statement, the variable price will reference the value. price = int(82.934) A. 82 D. 80 B. 83 E. False C. 82.9 3. What is the purpose of RAM in a computer? A. Store data after a machine has turned off B. Allow you to connect to the Internet C. Makes your hard drive run faster D. Helps keep heat consumption down E. Keeps active programs and data in short term memory available for usage 4. What is the value of val in the following expression if x = 4, y = 3, and z = 6? val = x < y or z > x A. True D. 5 B. False E. x C. 8 Answer E A E A 5. True / False: The last item in a list has the index -1. TRUE 6. What would be the value of the variable nums after the execution of the following code? nums = [1, 2, 3, 4] nums[3] = 10 A. [1, 2, 3, 10] D. [10] B. [1, 2, 10, 4] E. The code is invalid. C. [1, 10, 10, 10] 7. You want a variable that keeps track of the number of students in each class section at UVa. The best type for that variable to be is: A. str D. int B. bool E. dict C. list A E

CS 111X - Spring 2016 - Final Exam 3/10 Computing ID: Question 8. Ambiguity in a programming language can be a problem because: A. Designing algorithms that are clear and efficient is tough. B. Code has to be readable by others. C. Computers only do exactly what they are told to do. D. Ambiguous languages run slower than static languages. E. All of the above. 9. Which of the following is not a useful tip for the process of problem solving? A. Break complex problems into smaller problems B. Expect future reuse of code C. Find out as much info as you can D. Never copy your existing code E. Write out your algorithm before starting to code 10. True/False: If a whole paragraph is included in a single string, the split() method can be used to obtain a list of the words included in the paragraph. 11. True/False: Both of the following for clauses would generate the same number of loop iterations: for num in range(6) and for num in range(1,7) 12. What is the index of the last item found in a dictionary? A. 0 D. A dictionary is not indexed by a number B. 1 E. The key of the first item in the dictionary C. len(dictionary) - 1 13. What is the best thing to use to find all phone numbers in a large text document? A. Beautiful Soup D. regular expressions B. str methods E. my best friend C. phone_number_finder 14. The purpose of a library, like cimage or gamebox, is to: A. Allow your code to compile B. Prevent you from causing a stack overflow error C. Provide extra functionality for you to use in your program D. Enable PyCharm to use the optimization routines E. Allow for the use of the lambda functions 15. The following line of code will do what when put in the double loop of our image manipulation function: new_image.setpixel(old_image.width - col-1, row, old_pixel) A. Flip an image on the y axis B. Rotate the image 90 degrees clockwise C. Turn the image grayscale D. Resize the image to 50% E. Create a negative image Answer C D TRUE TRUE D D C A

CS 111X - Spring 2016 - Final Exam 4/10 Computing ID: Functions [30 pts total] 16. Write a function called word_wrap that takes a paragraph of text as a string and prints it to the screen such that each line is as close to 80 characters long as possible without going over. You should not try to split up words (such as with a hyphen). For example, if a line is currently at 78 characters long and the next word is summertime, you should start the next line with summertime. [10 pts] def word_wrap(string): words = string.split( " " ) lines = [ "" ] pos = 0 for word in words: if len ( lines [pos]) + len (word) < 80 : lines [pos] = lines [pos] + " " + word else : pos += 1 lines.append(word) for line in lines : print (line) 10 pts: Everything works, code is readable, good variable names, good formatting 8 pts: Minor errors in code - perhaps bad loop, incorrect algorithm, not printing correctly 6 pts: Multiple minor errors in code - multiple problems like those listed above 4 pts: Major errors in code - no chance correct answer is printed, major readability problems 2 pts: Code attempt is somewhat reasonable

CS 111X - Spring 2016 - Final Exam 5/10 Computing ID: 17. Write a function called most_common_names that takes a list of names and returns the name that appears the most often. If there is a tie, print just one of the names - it doesn t matter which. HINT: lists have a function called.count(x) that returns the number of times x appears in the list. [10 pts] def most_common_names(names_list): max_count = 0 max_name = "" for name in names_list: if max_count < names_list.count(name): max_count = names_list.count(name) max_name = name return max_name 10 pts: Everything works, code is readable, good variable names, good formatting 8 pts: Minor errors in code - perhaps bad loop, incorrect algorithm, not printing correctly 6 pts: Multiple minor errors in code - multiple problems like those listed above 4 pts: Major errors in code - no chance correct answer is printed, major readability problems 2 pts: Code attempt is somewhat reasonable 18. When executed, what is output by the following code fragment? [5 pts] 5.0 0.2_(3 pts: one right) def helper2(y, x): return x/y, y/x def helper(y, x): return helper2(x, y) x = 10 y = 2 x,y = helper(x,y) print (x,y) 19. When executed, what is output by the following code fragment? [5 pts] [2] 1_(3 pts: one right) def helper(x, y ): -1 if missing [] x[ 0 ] = 2 y = "2" x = [ 1 ] y = "1" helper(x, y)

CS 111X - Spring 2016 - Final Exam 6/10 Computing ID: print (x, y) Programming [20 pts total] 20. Write a program that will compare two text files line-by-line and print the differences between them. For example, assume you have the following two files: file_1.txt Here is some text that we can compare with another file. Even with a blank line! file_2.txt Here is some text that I can compare with another file... Even with a blank thingy! And an extra line! Notes: Your program should report any line that is different in any way between the two files. If a line is inserted in the middle of one file but not another, then every line below is probably going to be considered different. Treat this as a 1-to-1 comparison, line-by-line. You must handle the case that one file may be longer than the other. Print [none] if a line exists in one file but not the other. The first line of the file is Line: 0. You do NOT have to write a function for this problem - just code that does the job is fine. For the two example files above, an execution of your program should look like this: First file: file_1.txt Second file: file_2.txt Line: 1 < text that we can > text that I can Line: 3 < another file. > another file... Line: 6 < blank line! > blank thingy! Line: 7 < [none] > And an extra line!

CS 111X - Spring 2016 - Final Exam 7/10 Computing ID: 20. Only code on this page will be graded! So practice on scratch paper if needed! file_name_1 = input( First file: ) File_name_2 = input( Second file: ) file_1 = open (file_name_1, "r" ) file_2 = open (file_name_2, "r" ) file_1_lines = [] file_2_lines = [] for line in file_1: file_1_lines.append(line.strip()) for line in file_2: file_2_lines.append(line.strip()) loops = max ( len (file_1_lines), len (file_2_lines)) for pos in range (loops): if pos >= len (file_1_lines): print ( "Line:", pos) print ( "<", "[none]" ) print ( ">", file_2_lines[pos]) elif pos >= len (file_2_lines): print ( "Line:", pos) print ( "<", file_1_lines[pos]) print ( ">", "[none]" ) elif file_1_lines[pos]!= file_2_lines[pos]: print ( "Line:", pos) print ( "<", file_1_lines[pos]) print ( ">", file_2_lines[pos]) 5 pts: file management - opening files, reading files, etc 5 pts: overall algorithm - works and efficient 5 pts: code structure - correct loops, variables, etc 5 pts: handles extra lines on one file correctly

CS 111X - Spring 2016 - Final Exam 8/10 Computing ID: S hort Answer [20 pts total; 5 pts each] Please limit your answers to the lines provided. 21. What is the difference between a dynamically typed and statically typed language? Dynamic languages store data types with the value; statically typed store types with the variable. 5 pts: discusses both correctly. 3 pts: discusses one correctly 22. Describe the basic algorithm for turning an image into grayscale. No code is needed here. Double loop to go through each pixel. For each pixel, take the average of the RGB values to get the intensity of each pixel, representing its gray value. Put that pixel in the new image. Must have: loop and average of RGB values - 5 pts: both, 3 pts: one 23. Describe the fundamental differences between a list and a dict, including when you would use each. List is an ordered linear structure for multiple values; dict is a key/value structure and is unordered 5 pts: both, 3 pts: one 24. Describe the basic algorithm a gamebox game (i.e. the game loop ). In other words, what appears in the tick() function, in what general order, and what does each part do. Clear the screen, move everything that needs it, detect collisions and handle, handle input, draw everything, camera.draw() 5 pts: basic structure is good, mentions most things above 3 pts: structure is okay, mentions at least 3 things above

CS 111X - Spring 2016 - Final Exam 9/10 Computing ID: Have a great summer break! Thanks for taking CS 1110/1111 this semester! SCRATCH PAPER - Nothing on this page will be graded!

CS 111X - Spring 2016 - Final Exam 10/10 Computing ID: SCRATCH PAPER - Nothing on this page will be graded!