CS 1301 Exam 3 Fall 2014

Similar documents
CS 2316 Exam 1 Spring 2014

CS 1301 Exam 3 Spring 2014

CS 1301 Exam 1 Fall 2010

CS 1301 Exam 2 Fall 2013

CS 1301 Exam 2 Spring 2014

CS 1301 Exam 1 Fall 2010

CS 1301 Exam 3 Spring 2012

CS 1301 Exam 1 Fall 2011

CS 2316 Exam 4 Fall 2012

CS 1301 Exam 1 Spring 2011

CS 2316 Exam 4 Fall 2011

CS 2316 Exam 1 Spring 2013

CS 1301 Exam 2 A Fall 2015

CS 1301 Exam 1 Spring 2014

CS 1301 Exam 3 A Spring 2015

CS 1301 Exam 2 Fall 2010

CS 1301 Exam 1 Fall 2014

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

CS 1301 Exam 2 Fall 2014

CS 2316 Exam 4 Spring 2013

CS 1301 Exam 2 A Fall 2015

CS 1803 Fall 2010 Exam 1

CS 1301 Exam 1 Fall 2014

CS 2316 Exam 4 Fall 2012

CS 1803 Fall 2010 Exam 1

CS 1301 Exam 1 Spring 2014

CS 2316 Exam 4 Fall 2014

CS Name : Grading TA:

CS Exam 2 - Spring 2010

CS 2316 Exam 3 Fall 2011

CS 2316 Exam 4 Fall 2011

Exam Percentage: / 55 = %

CS 1301 Exam 1 Fall 2013

CS 1301 Exam 1 Fall 2013

CS 1301 Exam 3 Fall 2010

CS 1301 Exam 1 Spring 2015

CS 2316 Exam 3 Spring 2013

CS 2316 Exam 4 Spring 2012

CS 2316 Exam 3 Fall 2012

CS 1301 Post Exam 3 Practice Spring 2016

CS 2316 Exam 2 Summer 2011

Question Possible Points Earned Points Graded By GUI 22 SQL 24 XML 20 Multiple Choice 14 Total Points 80

Your (printed!) Name: CS 1803 Exam 2. Grading TA / Section: Monday, Oct 25th, 2010

CS Exam 3 - Spring 2010

CS Exam 3 - Spring 2010

CS 2316 Exam 3 Summer 2014

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.

Question: Total Points: Score:

Instructor: Yu Wang 11/16/2012

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

Question: Total Points: Score:

Section 003 Fall CS 170 Exam 1. Name (print): Instructions:

Question: Total Points: Score:

CS 110 Exam 2 Spring 2011

Question: Total Points: Score:

Question: Total Points: Score:

CS 170 Exam 2. Version: A Fall Name (as in OPUS) (print): Instructions:

Question: Total Points: Score:

CS 1301 Exam 1 Answers Fall 2009

CS 1301 Exam 1 Fall 2009

CS 190 Exam 2 Fall 2014

Question: Total Points: Score:

This exam has 10 pages including the title page. Please check to make sure all pages are included.

Question: Total Points: Score:

: Intro Programming for Scientists and Engineers Final Exam

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

Question: Total Points: Score:

CS 155 Exam 2 Spring 2015

CS 190 Exam 1 Fall 2010

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

CS 170 Exam 2. Version: A Spring Name (as in OPUS) (print): Instructions:

Question: Total Points: Score:

CS 111X - Fall Test 1

Question: Total Points: Score:

CS 170 Exam 2. Version: A Spring Name (as in OPUS) (print): Instructions:

CS 170 Exam 2. Section 004 Fall Name (print): Instructions:

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

CS 170 Exam 1. Version: B Fall Name (as on OPUS):

Question: Total Points: Score:

CS 170 Exam 1. Version: C Fall Name (as on OPUS):

Place your name tag here

CS 1316 Exam 1 Summer 2009

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

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

Question: Total Points: Score:

CS 1322 Test 2 - Version 1 Tuesday June 24 th

Question: Total Points: Score:

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

CS 110 Exam 2 Fall 2011

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

CS 111X - Spring Final Exam - KEY

CS 1316 Exam 2 Summer 2009

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

CS170 (005): Introduction to Computer Science Exam 2

Structure and Interpretation of Computer Programs

(the bubble footer is automatically inserted into this space)

CSE 131 Introduction to Computer Science Fall Exam I

Structure and Interpretation of Computer Programs

CSE 131 Introduction to Computer Science Fall Exam I

Short Answer Questions (40 points)

Transcription:

CS 1301 Exam 3 Fall 2014 Name : Section TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam in compliance with the Academic Honor Code of Georgia Tech. Do NOT sign nor take this exam if you do not agree with the honor code. Devices: If your cell phone, pager, PDA, beeper, ipod, or similar item goes off during the exam, you will lose 10 points on this exam. Turn all such devices off and put them away now. You cannot have them on your desk. Academic Misconduct: Academic misconduct will not be tolerated. You are to uphold the honor and integrity bestowed upon you by the Georgia Institute of Technology. Keep your eyes on your own paper. Do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than a proctor for ANY reason in ANY language in ANY manner. Do NOT share ANYTHING during the exam. (This includes no sharing of pencils, paper, erasers). Follow directions given by the proctor(s). Stop all writing when told to stop. Failure to stop writing on this exam when told to do so is academic misconduct. Do not use notes, books, calculators, etc during the exam. Time: Don t get bogged down by any one question. If you get stuck, move on to the next problem and come back once you have completed all of the other problems. This exam has 4 questions on 8 pages including the title page. Please check to make sure all pages are included. You will have 50 minutes to complete this exam. I commit to uphold the ideals of honor and integrity by refusing to betray the trust bestowed upon me as a member of the Georgia Tech community. I have also read and understand the requirements outlined above. Signature: 1

Question 1. Multiple Choice 3 2. Vocabulary 10 3. Extract 21 14 4. Flip 10 Total: 37 Points Score 1. (3 points) For each of the following multiple choice questions, indicate the most correct answer! Indicate your selected answer by circling it. (a) [1 pt] Convert 213 10 to binary (base 2): A. 10001111 B. 11100111 C. 10111001 D. 11010100 E. 11010101 F. 11110011 (b) [1 pt] Which of the following is true about the keys in a dictionary? A. An integer can be a key. B. A list can be a key. C. A dictionary can be a key. D. All keys must be mutable. E. All of the above are False. (c) [1 pt] The following code is executed: adict = {"one":"uno", "two":"dos"} alist = [] for element in adict: alist.append(element) Which of the following is correct? A. alist will contain tuples of the key/value pairs in adict B. alist will contain the keys of adict C. alist will contain the values of adict D. An error will occur. 2

2. (10 points) Match each term in the word bank with one of the statements below. algorithm block recursion boolean expression element functional programming iteration map reduce conditional statement mutable dictionary The process of a function calling itself. Sequence of statements with the same indentation level. A segment of code that evaluates to a True or False value. A formal sequence of instructions like a program or recipe. One of the values in a sequence. Selected by the bracket operator. A kind of compound data types whose elements can be assigned new values. The repeated execution of a set of statements using a loop or recursion. A statement that controls the flow of execution depending on a condition. A higher-order function that processes a sequence in some order and accumulates a return value. A higher-order function that applies a given function to a sequence of elements (such as a list) and returns a sequence of results. Solution: 3

recursion block Boolean Expression Algorithm Element mutable iteration The process of a function calling itself. Sequence of statements with the same indentation level. A segment of code that evaluates to a True or False value. A formal sequence of instructions like a program or recipe. One of the values in a sequence. Selected by the bracket operator. A kind of compound data types whose elements can be assigned new values. The repeated execution of a set of statements using a loop or recursion. conditional statement A statement that controls the flow of execution depending on a condition. reduce map A higher-order function that processes a sequence in some order and accumulates a return value. A higher-order function that applies a given function to a sequence of elements (such as a list) and returns a sequence of results. 4

3. (14 points) Write a function named extract21 that takes in one parameter, the name of a text file, as a string. This text file contains the names and ages of a group of students. (lastname,firstname, age). Open the file, read in the data, and extract only those students who are 21 or over. Sort the data by lastname. (If the lastnames are the same, you may use the firstname and then the age to break ties). Write the extracted data to a file called over21.txt using the same (lastname, firstname, age) format. Example Input and Output: infile.txt: -------------------------------------- Kassem, Samantha, 21 Ferenzio, Bobbay, 18 Avery, Jordan, 21 Smith, Scotty, 20 Styles, Harry, 22 Diaddigo, Josh, 18 extract21("infile.txt") over21.txt: Avery, Jordan, 21 Kassem, Samantha, 21 Styles, Harry, 22 Solution: def extract21(filename): readfile = open(filename) nestedlist = [] for i in readfile.readlines(): splitup = i.split(",") nestedlist.append([splitup[0], splitup[1], int(splitup[2])]) nestedlistover21 = [] for i in nestedlist: if i[2] >= 21: nestedlistover21.append(i) nestedlistover21.sort() newfile = open("over21.txt", "w") 5

for i in nestedlistover21: newfile.write(i[0] + "," + i[1] + ", " + str(i[2]) + "\n") newfile.close() readfile.close() Grading: +1 Correct function definition +1 Opens the file +2: Gets each line from the file. +2: Splits the line on commas +2: Converts 3rd item to an int or float +2: Compares each age to 21 and extracts data +2: Sorts the output data correctly +1: writes output file correctly. +1: Closes the output file 6

This page intentionally left blank. You may use it for scratch paper. If you place an answer on this page, box it, indicate which problem it is for by number, and BE SURE TO WRITE Answer on last page at the problem location! 7

4. (10 points) Write a function flip takes a picture object as a parameter. It should return a new picture that is an upside down version of it s input. Another way of thinking about this is that the bottom row of the output picture should look exactly like the top row of the input picture. Your function should not modify the input picture. Solution: def flip(p): newp = makepicture( getwidth(p), getheight(p)) # or copypicture(p) for x in range( getwidth(p)): for y in range (getheight(p)): pix = getpixel(p,x,y) newpix = getpixel(newp, x, getheight(p) -1 -y ) oldcolor = getrgb(pix) #Could also do red/green/blue separately setrgb(newpix, oldcolor) return newp Grading: +1 correct header +2 making new picture same size as old picture +1 itterating through all of the pixels +1 getting the color(s) from the old pixel +1 putting the same color(s) into (any) new pixel +3 calculating CORRECT new pixel to put the color into. +1 returning the new picture. 8