CS 1301 Exam 2 Fall 2010

Similar documents
CS 1301 Exam 1 Fall 2010

CS 1301 Exam 2 A Fall 2015

CS 1301 Exam 1 Fall 2011

CS 2316 Exam 1 Spring 2014

CS 1301 Exam 2 A Fall 2015

CS 1301 Exam 3 Spring 2014

CS 1301 Exam 1 Fall 2014

CS 1301 Exam 1 Fall 2010

CS 1301 Exam 1 Fall 2014

CS 2316 Exam 1 Spring 2013

CS 1301 Exam 1 Spring 2014

CS 1301 Exam 2 Fall 2013

CS 2316 Exam 4 Fall 2012

CS 1301 Exam 3 Spring 2012

CS 1301 Exam 2 Fall 2014

CS 1301 Exam 3 A Spring 2015

CS 1301 Exam 1 Spring 2011

CS Name : Grading TA:

CS 2316 Exam 4 Spring 2013

CS 1301 Exam 1 Spring 2014

CS 1301 Exam 3 Fall 2014

CS 2316 Exam 4 Fall 2011

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

CS 1301 Exam 2 Spring 2014

CS 1301 Exam 1 Fall 2013

CS 1301 Exam 1 Fall 2013

Exam Percentage: / 55 = %

CS 1301 Exam 1 Spring 2015

CS 2316 Exam 4 Fall 2011

CS 2316 Exam 4 Fall 2012

CS 1803 Fall 2010 Exam 1

CS 2316 Exam 4 Fall 2014

CS 1301 Exam 3 Fall 2010

CS 2316 Exam 3 Fall 2011

CS 1803 Fall 2010 Exam 1

CS 2316 Exam 3 Fall 2012

CS 2316 Exam 3 Spring 2013

CS Exam 2 - Spring 2010

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

CS 2316 Exam 2 Summer 2011

CS 1301 Post Exam 3 Practice Spring 2016

CS 2316 Exam 4 Spring 2012

CS Exam 3 - Spring 2010

CS Exam 3 - Spring 2010

CS 2316 Exam 3 Summer 2014

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

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.

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

CS 1301 Exam 1 Answers Fall 2009

CS 1301 Exam 1 Fall 2009

CS 111X - Fall Test 1

: Intro Programming for Scientists and Engineers Final Exam

CS 110 Exam 2 Spring 2011

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

CS 190 Exam 1 Fall 2010

CS 190 Exam 2 Fall 2014

Question: Total Points: Score:

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

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

Question: Total Points: Score:

Instructor: Yu Wang 11/16/2012

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

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

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

Question: Total Points: Score:

Question: Total Points: Score:

Question: Total Points: Score:

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

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

Question: Total Points: Score:

CS 155 Exam 2 Spring 2015

Your Name: Your TA's Name: 1 / 10 CS 1301 CS1 with Robots Fall 2008 Exam 3

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

Question: Total Points: Score:

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

The Practice of Computing Using PYTHON

Question: Total Points: Score:

Place your name tag here

Question: Total Points: Score:

CS 111X - Spring Final Exam - KEY

CS 1301 Final Exam Review Guide

CSE 131 Introduction to Computer Science Fall Exam I

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

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

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

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

Question: Total Points: Score:

Final Exam(sample), Fall, 2014

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

1 Fall 2017 CS 1110/1111 Exam 3

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

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

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

Python Review IPRE

CS 1322 Test 2 - Version 1 Tuesday June 24 th

CS150 Sample Final. Name: Section: A / B

Structure and Interpretation of Computer Programs

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

University of Maryland College Park Dept of Computer Science CMSC106 Fall 2016 Midterm I

Short Answer Questions (40 points)

Transcription:

CS 1301 Exam 2 Fall 2010 Name : Grading TA: 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 7 questions on 10 pages including the title page. Please check to make sure all pages are included. You will have 50 minutes to complete this exam. 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. I have also read and understand the requirements outlined above. Do NOT sign nor take this exam if you do not agree with the honor code. Signature: Question Points Score 1. Vocabulary 9 2. Dictionaries & Tuples 10 3. Legal or not? 9 4. removefirst 5 5. Short Answer 11 6. studentreadlines 10 7. Run Away 20 Total: 74 1

1. (9 points) For each of the following vocabulary terms, write a concise 1-2 sentence definition. Be brief, and to the point. (a) [3 pts] algorithm Solution: A finite set of unambiguous instructions performed in a prescribed sequence to achieve a goal. (b) [3 pts] boolean expression Solution: A python statement that evaluates to either True or False. Typically contains a comparison operator ( <, >, <=, >=, ==,!=) and may contain boolean operators such as AND, OR, or NOT. (c) [3 pts] conditional statement Solution: A statement that controls the flow of execution depending on some condition. In Python the keywords if, elif, and else are used for conditional statements. 2. (10 points) Read the following pieces of code. Determine whether they will be executed successfully or not. If yes, show the result that would be printed. If not, explain why not. (a) [2 pts] mytuple1 = (1,2,3) mytuple1.append(4) print mytuple1 Solution: No. Because tuple is immutable, so there is not an append function for tuple. (b) [2 pts] mytuple2 = (1,2,3) mytuple3 = (4) print mytuple2+mytuple3 Solution: No. Because mytuple3 is not a tuple but an int. (c) [2 pts] mylist=[0,3,4,1] mylist.remove(3) print mylist 2

Solution: Answer: Yes. [ 0, 4, 1] (d) [2 pts] mydictionary1={ a:1, b:2, c:3} mydictionary1[d]=4 print mydictionary1 Solution: No. Because a, b, c, d here are neither characters nor strings. They will be treated as undefined variable names. (e) [2 pts] mydictionary2={ 10 : 1, 20 : 2, 30 : 3} print mydictionary2[1] Solution: Answer: No. Because elements in dictionary can only be accessed by keys but not indexes. In mydictionary2, 1 is not one of the keys. 3. (9 points) Beside each expression, write LEGAL if the expression is legal python code, or ER- ROR if the expression would cause an error. Assume that mylist, mytuple, and mystring are a list, a tuple, and a string, respectively, and all contain at least one element. 1. mylist = mylist + [4] 2. mylist.append(4) 3. del mylist[0] 4. mytuple = mytuple + (4,) 5. mytuple.append(4) 6. del mytuple[0] 7. mystring = mystring + 4 8. mystring.append(4) 9. del mystring[0] Solution: Grading: +1 for each correct answer. 1) mylist = mylist + [4] LEGAL 2) mylist.append(4) LEGAL 3) del mylist[0] LEGAL 3

4) mytuple = mytuple + (4,) LEGAL 5) mytuple.append(4) ERROR 6) del mytuple[0] ERROR 7) mystring = mystring + 4 LEGAL 8) mystring.append(4) ERROR 9) del mystring[0] ERROR 4

4. (5 points) Write a function called removefirst that accepts a list as a parameter.it should remove the value at index 0 from the list. Note that it should not return anything (returns None). Note that this function must actually modify the list passed in, and not just create a second list with the first item removed. You may assume the list you are given will have at least one element. For example: >>> a = [1, 2, 3, 4] >>> b = removefirst(a) >>> print a [2, 3, 4] >>> print b None Solution: def removefirst(alist): del alist[0] return None #Or a blank line. Grading: 1 pt - Correct def statement 2 pt - Correctly removes first element using del keyword. 2 pt - returns None, either deliberately, or by default. 5

5. (11 points) For each of the following questions, give a brief answer: (a) [1 pt] What does it mean for a compound data type to be mutable? Solution: It means that you can change items (elements) within the compound data type. (b) [1 pt] Which compound data types are mutable? Solution: Lists and Dictionaries are mutable. (c) [1 pt] Which compound data types are immutable? Solution: Strings and Tuples are immutable. (d) [4 pts] Assume each of the following lines is entered in the IDLE shell one at a time. Circle any of the lines that produces an error. If no errors are found then write what is printed (from a and b). a = [[[1, 2, 3, 4, 5],[6,7,8]],9] a[-1] = 200 b = a[:] b[0][0][3] = 17 print a print b Solution: [[[1, 2, 3, 17, 5], [6, 7, 8]], 200] [[[1, 2, 3, 17, 5], [6, 7, 8]], 200] Grading: +2 for each line... (e) [4 pts] A text file named fruits.txt contains the following three lines: Apple Blueberry Cantaloupe The following code is run: f = open("fruits.txt", "r") f.readline() s = f.readline() f.close() 6

f = open("output.txt", "w") f.write(s + "\n") f.write("orange\n") f.close() What does the file output.txt contain? Solution: Answer: Blueberry Orange Grading: +2 for each correct line. -1 for each incorrect line, -1 if they don t draw them vertically, or indicate the newline character. 7

6. (10 points) Write a function called studentreadlines that accepts the name of a file as a string parameter. The function will return a list containing each individual line of the file. For example, if the file contained the following text: Hello, guys! Good Luck on your test! Hope you enjoy your weekend! Your function would return: [ Hello, guys!\n, Good Luck on your test!\n, Hope you enjoy your weekend!\n ] Solution: def studentreadlines( filename ): f = open( filename, "r") data = f.readlines()a f.close() return data Grading: 2 points for the header 2 points for opening the file 2 points for closing the file 2 - get the list of lines 2 - Returns the list. -1 for hardciding 3 lines -1 for f.close without () 8

7. (20 points) Write a function named runaway that accepts an integer as a parameter. The integer corresponds to how long your function should run, in seconds, before returning. While running, your function should get the values of the robots IR sensors (not Obstacle sensors) and any time it detects something is behind the robot with either sensor, it should move forward at full speed until the sensor no longer detects anything. (Then the robot should stop, either until the number of seconds is up, or until something else is detected behind the robot.) When your function returns, it should return None. Make sure that, no matter what, your robot stops and the function returns when the time is up! You may assume that the myro library is already loaded and that your robot is already connected (init has been called) to the computer. Solution: def runaway(time): while timeremaining(time): if getir("left") == 0 or getir("right") == 0: forward(1) else: stop() stop() Grading: 2 point for correct header 6 points for checking the getir sensors (2 points if they only check one side of the sensors) 6 points for moving forward when either sensor is triggered (zeros) 6 points for stopping the robot and returning when the time is up. 9

Extra Credit Questions: 1. What is the decimal representation for the binary number (101101) 2 (1 pt)? 2. What is the binary representation for the decimal number (15) 10 (1 pt)? 3. What is the hexadecimal representation for the decimal number (31) 10 (1 pt)? 4. What is the name of the Braitenberg vehicle that moves away from the light (1 pt)? 5. What does CSS stand for (1 pt)? 10