Difference between revisions of "CSC111 Final Exam 2015"
(52 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | |||
+ | <bluebox> | ||
+ | This exam is a take-home exam given under the rules of the [http://www.smith.edu/sao/handbook/socialconduct/honorcode.php Smith College Honor-Code]. Please make sure you read it and understand it. | ||
+ | <br /> | ||
+ | The exam is open book, open notes, and open Web. | ||
+ | <br /> | ||
+ | You have to do the work '''individually'''. You cannot seek help from anybody for this exam. The TAs will not have consulting hours, and will not be allowed to answer questions relating to Python or the class material. All questions relating to this Final should be directed to your instructor, and posted on Piazza. Posts on piazza should not contain any code. Only questions meant to clarify the exam are allowed. No debugging-related questions will be answered. | ||
+ | <br /> | ||
+ | The deadline for the exam is Friday, ''May 8, at 4:00 p.m.''' While you are given 8 days on this exam, the programming should not take you more than a day, two at most, so organize your time well. No extensions will be granted beyond the due date and time. | ||
+ | </bluebox> | ||
+ | <br /> | ||
<onlydft> | <onlydft> | ||
+ | =Problem 1= | ||
+ | <br /> | ||
+ | This problem is based on [[CSC111_Homework_11_2015| Homework 11]]. In Problem 1 of Homework 11, the user is asked to enter the name of a file, and then the program outputs statistics about the data stored in the file. In this exam problem, the user may enter the name of '''several files''', one after the other. There is no limit on the number of files the user enters. The exam program then outputs the coldest temperature recorded over all the cities specified, followed by groups of city name, month, and year when it was recorded. For example, if the user specifies two files, and the coldest temperature in the first file is -4.2, and the coldest in the second file is -5.7, then the program only output -5.7, along with the name of the city associated with the second file, along with the month and year when -5.7 was recorded. If -5.7 is found several times in the tmin column of the file, then all occurrences are reported (see Example section below). | ||
− | |||
<br /> | <br /> | ||
− | + | ==Data Files== | |
+ | <br /> | ||
+ | * Please download a new set of temperature-data files from the Smith URL indicated in Homework 11. In particular, the armaghdata.txt and bramemardata.txt have been slightly modified to ensure that the coldest temperature is found in both cities. | ||
+ | * When your program is tested, it will be given different files that will have been modified to have common lowest temperatures, to fully test your program, and it is possible that all the files will contain the same lowest temperature. It is also possible that a file may contain only 1 line of temperature data. | ||
+ | <br /> | ||
+ | ==Requirements== | ||
+ | <br /> | ||
+ | * Store your program in a file called '''final1.py'''. | ||
+ | * Make sure your program contains a '''main()''' function, and that the execution starts with main, with this code, which should be the last 2 lines of your program: | ||
+ | <br /> | ||
+ | ::<source lang="python"> | ||
+ | if __name__=="__main__": | ||
+ | main() | ||
+ | </source> | ||
+ | <br /> | ||
+ | * The program should get the names of the temperature files on one long line (see Example section below). | ||
+ | * If one of the names given is invalid (the file does not exist), your program should simply print "Invalid file name given" and stop, without outputting any temperature information, even if the other file names are valid. (The test program will check for the presence of the word "invalid" in your output.) | ||
+ | <br /> | ||
+ | ==Example== | ||
+ | <br /> | ||
+ | * Here is an example of the interaction to be expected between the user and the program, where the user input is underlined: | ||
+ | <br /> | ||
+ | |||
+ | File names? <u>armaghdata.txt</u> | ||
+ | |||
+ | -8.6 Armagh Dec 1878 | ||
+ | |||
+ | |||
+ | File names? <u>bradforddata.txt braemardata.txt</u> | ||
+ | |||
+ | -8.6 Braemar Jan 1963 Braemar Feb 1963 | ||
+ | |||
+ | |||
+ | File names? <u>armaghdata.txt ballypatrickdata.txt bradforddata.txt braemardata.txt</u> | ||
+ | |||
+ | -8.6 Armagh Dec 1878 Braemar Jan 1963 Braemar Feb 1963 | ||
+ | |||
+ | |||
+ | File names? <u>armaghdata.txt ballypatrickdata.txt bradforddata.txt braemardata.txt notAGoodFileName.zip</u> | ||
+ | |||
+ | Invalid file name. | ||
+ | |||
+ | <br /> | ||
+ | * Notice how the user enters all the files of interest on one line. | ||
+ | * The program outputs the coldest temperature (-8.6, found in the tmin column of the files), followed by groups of 3 fields, where the first one is the city name (not the file name), the month (expressed as 3 letters), and the year. | ||
+ | * All fields are printed on one line only, and separated by spaces. | ||
+ | * If different cities contain the same lowest temperature, they are listed in alphabetical order. For example, Armagh is listed before Braemar in the result line, above. | ||
+ | * Use this prompt to ask the user to enter the file names: "File names?" | ||
+ | <br /> | ||
+ | ==Submission== | ||
+ | <br /> | ||
+ | * Submit your program the Final Problem 1 section on Moodle. | ||
+ | <br /> | ||
+ | =Problem 2: Frogger Game= | ||
+ | <br /> | ||
+ | <center><videoflash>plgm_p2zAek</videoflash></center> | ||
+ | <br /> | ||
+ | (if the video does not show in the page, you can watch it on YouTube: [https://www.youtube.com/watch?v=plgm_p2zAek https://www.youtube.com/watch?v=plgm_p2zAek]) | ||
+ | Your assignment is to write a program that uses graphics, and that implements the game illustrated in the video, with a few additional features. | ||
+ | <br /> | ||
+ | Note that the cars appearing on the left of the screen in the video, blink. This is a side-effect of the graphics library, and not a voluntary feature of the program. | ||
+ | <br /> | ||
+ | ==Frog== | ||
+ | <br /> | ||
+ | [[Image:frog3.gif|right]] | ||
+ | You can use the frog image shown on the right for your game, or use one you will have found on the Web. Or you can draw it using ovals and/or circles. The URL for the image on the right is: [http://cs.smith.edu/dftwiki/images/f/f6/Frog3.gif cs.smith.edu/dftwiki/images/f/f6/Frog3.gif]. If you use your own image, make sure you call it '''Frog3.gif'''. When your program is tested, the Frog3.gif image shown here will be the one your program will find and use. | ||
+ | <br /> | ||
+ | ==The Banner== | ||
+ | <br /> | ||
+ | The banner at the top of the screen is an object of a class called '''Banner''', which is given below, along with a main program that illustrates how to use it. | ||
+ | <br /> | ||
+ | ::<source lang="python"> | ||
+ | # bannerDemo.py | ||
+ | # D. Thiebaut | ||
+ | # A short program illustrating the use of a banner in | ||
+ | # graphics. | ||
+ | from graphics import * | ||
+ | WIDTH=800 | ||
+ | HEIGHT=600 | ||
− | + | class Banner: | |
+ | def __init__( self, message ): | ||
+ | """constructor. Creates a message at the top of the graphics window""" | ||
+ | self.text = Text( Point( WIDTH//2, 20 ), message ) | ||
+ | self.text.setFill( "black" ) | ||
+ | self.text.setTextColor( "black" ) | ||
+ | self.text.setSize( 20 ) | ||
+ | |||
+ | def draw( self, win ): | ||
+ | """draws the text of the banner on the graphics window""" | ||
+ | self.text.draw( win ) | ||
+ | self.win = win | ||
+ | |||
+ | def setText( self, message ): | ||
+ | """change the text of the banner.""" | ||
+ | self.text.setText( message ) | ||
+ | |||
+ | def main(): | ||
+ | # creates a window | ||
+ | win = GraphWin( "Demo", WIDTH, HEIGHT ) | ||
− | + | # draw the banner at the top | |
+ | banner = Banner( "Demo. Please click the mouse!" ) | ||
+ | banner.draw( win ) | ||
− | = | + | # wait for the user to click the mouse before continuing... |
+ | p = win.getMouse() | ||
+ | # update the banner | ||
+ | banner.setText( "Mouse clicked at Point({0:1}, {1:1})" | ||
+ | .format( p.getX(), p.getY() ) ) | ||
+ | |||
+ | # wait again, and update the banner one more time | ||
+ | p = win.getMouse() | ||
+ | banner.setText( "Mouse clicked again, at Point({0:1}, {1:1})" | ||
+ | .format( p.getX(), p.getY() ) ) | ||
+ | |||
+ | win.getMouse() | ||
+ | win.close() | ||
+ | main() | ||
+ | </source> | ||
+ | <br /> | ||
+ | ==Implementation== | ||
+ | <br /> | ||
+ | * Call your program '''final2.py''' | ||
+ | * You '''must''' use objects to define the cars. | ||
+ | * The number of cars used by the program is fixed and does not grow as the game evolves. In the video, the number of cars is 3, but you can use more. When a car disappears on one end of the screen it reappears on the other side, after a short delay. The delay is up to you. | ||
+ | * The frog moves up or down by a fixed amount. To make the frog move up, the user must click the mouse in the area of the window above the road. To make the frog move down, the user clicks the mouse in the area of the window below the road. | ||
+ | * The frog "dies," or loses a ''life point'' when it is run over by a car. You are free to determine the conditions for which the program will determine that the car is running over the frog. In the video the top or bottom of the frog can overlap slightly the body of a car without triggering the program to detect an overlap. There is flexibility. | ||
+ | * The program automatically brings the frog back down to its initial position when a car runs over it, or when the frog has fully crossed the road. | ||
+ | <br /> | ||
+ | ==Grading== | ||
+ | <br /> | ||
+ | * Assuming that your program is well documented, and nicely organized with functions and classes, the following features will be worth various number of points. A grade of 100 will be given to a will documented and organized program that behaves similarly to the game illustrated in the YouTube video, but with two lanes of cars, one lane going left to right, one going right to left. The number of cars must remain constant, and cars disappearing on one end are made to reappear on the other side. | ||
+ | * Banner working correctly: 10 points | ||
+ | * Cars moving off the graphics window and reappearing on the other side: 10 points. | ||
+ | * Game stopping when the number of life points reaches 0: 10 points | ||
+ | * Frog and car intersection works well: 10 points | ||
+ | * Frog moved back to original position when run over, or when fully crossed: 10 points | ||
+ | * Frog moves up and down on mouse clicks: 10 points. | ||
+ | <br /> | ||
+ | ==Submission== | ||
+ | <br /> | ||
+ | * Submit your program in the Final Problem 2 area on Moodle. | ||
+ | <br /> | ||
+ | =Problem 3: Twitter= | ||
+ | <br /> | ||
+ | * Write a program called '''final3.py''' that asks the user for 3 pieces of information: | ||
+ | ::# the name of a file that contains tweets from or to @smithcollege | ||
+ | ::# a location of interest | ||
+ | ::# a keyword of interest | ||
+ | * The program then reads a file containing tweets, and outputs several pieces of information: | ||
+ | ::# the date and time of the earliest tweet stored in the file | ||
+ | ::# the date and time of the most recent tweet stored in the file | ||
+ | ::# the number of tweets whose location contains the ''location of interest'' entered by the user | ||
+ | ::# the number of tweets whose text contains the keyword of interest. | ||
+ | <br /> | ||
+ | ==Format of the File== | ||
+ | <br /> | ||
+ | * The format of the file provided to you and used to test your program, is illustrated by this simple example. | ||
+ | |||
+ | ---- | ||
+ | Date: Fri Mar 27 12:22:58 +0000 2015 | ||
+ | Text: #smithieslead MT @GlobalTiesUS: 1st female @afsatweets officer! Grad of @smithcollege | ||
+ | Screen name: smithcollege | ||
+ | Location: Northampton, MA | ||
+ | |||
+ | * Explanations: | ||
+ | :* A tweet is always preceded by a line of 4 dashes. | ||
+ | :* The second line is the date the tweet was created. You can discard the "+0000" field, which refers to a time zone. | ||
+ | :* The third line contains the name of the sender or repeater. Most of the tweets come from "@smithcollege" or "@presmccartney." | ||
+ | :* The fourth line contains the location associated with the tweet. | ||
+ | <br /> | ||
+ | ==Sample File== | ||
+ | * Click on this URL: [http://cs.smith.edu/dftwiki/media/twitterFeed.txt http://cs.smith.edu/dftwiki/media/twitterFeed.txt] and save the text that will display in your browser to a text file that you will call '''twitterFeed.txt''', in a directory of your choice on your computer. Do not edit the information in the file, and do not remove anything from it, as your program needs to be able to treat it "as is," and will be tested with another file, similar in format, but with different contents. | ||
+ | <br /> | ||
+ | == Interaction with the User== | ||
+ | <br /> | ||
+ | * Below is an example of an interaction with the solution program: | ||
+ | <br /> | ||
+ | File name? <u>twitterFeeeeeeeed.txt</u> | ||
+ | Invalid file name. Please reenter | ||
+ | File name? <u>twit.txt</u> | ||
+ | Invalid file name. Please reenter | ||
+ | File name? <u>twitterFeed.txt</u> | ||
+ | Location of interest? northampton | ||
+ | keyword of interest? Maya | ||
+ | --- Output --- | ||
+ | 252 tweets read | ||
+ | earliest: 20141110 02:21:14 | ||
+ | latest: 20150423 09:31:16 | ||
+ | Number of distinct locations: 24 | ||
+ | Number of times Location "northampton" appears: 114 | ||
+ | Number of times "Maya" appears in text: 5 | ||
+ | <br /> | ||
+ | * Your program must match this output as closely as possible, including the "---Output---" line. Remember that your program will be tested with a collection of tweets that will be different, and probably gathered in a different time period, so your program must locate the oldest and newest tweets ''found'', and not simply output the dates shown above! | ||
+ | * <font color="magenta">(Addition)</font>: The number of distinct locations is the number of different strings used to represent locations. "Northampton, MA" is distinct from "Northampton MA". "Northampton" is the same as "northampton". | ||
+ | * <font color="magenta">(Addition)</font>: You are free to make an empty location count as a unique location or not. So if the file contains 2 tweets, one with location "Northampton", and the other one with a blank location (only white space after the "Location: " string in the file), then that will count as either 1 or 2 distinct locations. Both answers are correct. | ||
+ | * Note also that the date has been modified by the program, and is output as an 8-digit quantity; the year first, followed by the month, followed by the day. Note also that April is represented by 04, and not 4. | ||
+ | <br /> | ||
+ | |||
+ | ==Requirements== | ||
+ | <br /> | ||
+ | * Make sure your program contains a '''main()''' function, and that the execution starts with main, with this code, which should be the last 2 lines of your program: | ||
+ | <br /> | ||
+ | ::<source lang="python"> | ||
+ | if __name__=="__main__": | ||
+ | main() | ||
+ | </source> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | ==Testing== | ||
+ | <br /> | ||
+ | * Test your program well. In particular, your program should be able not to crash if the file given to it contains only 1 entry, or if the file is empty. | ||
+ | * You can assume that all entries will always contain 4 fields (date, location, screen-name, and text). | ||
+ | * When looking for the number of unique locations found in the tweets, "Northampton, MA" and "Northampton, Massachusetts" count as 2 different locations. Basically if the lowercase string versions of two different locations are not equal, the locations are distinct. "Northampton MA" and "Northampton, MA" are distinct (because of the comma). "northampton" and "Northampton" are the same. "Northampton " and "Northampton" are the same (because the stripped strings are the same) | ||
+ | * <font color="magenta">(New addition)</font> When your program counts the number of tweets that match the "location of interest" selected by the user, it should look for ''partial'' matches in the location fields only. For example, if the user writes "amherst" as her location of interest, then the program will count "Amherst, MA", "South Amherst, MA", "North-Amherst, MA" as matching her selection. | ||
+ | <br /> | ||
+ | ==Submission== | ||
+ | <br /> | ||
+ | * Submit your program in the Final Problem 3 section. | ||
+ | <br /> | ||
+ | |||
+ | =Problem 4: Quiz= | ||
+ | <br /> | ||
+ | Answer the questions in the Quiz section of the Final Exam section, on Moodle. | ||
+ | <br /> | ||
</onlydft> | </onlydft> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | [[Category:CSC111]][[Category:Python]] |
Latest revision as of 17:22, 12 December 2015
This exam is a take-home exam given under the rules of the Smith College Honor-Code. Please make sure you read it and understand it.
The exam is open book, open notes, and open Web.
You have to do the work individually. You cannot seek help from anybody for this exam. The TAs will not have consulting hours, and will not be allowed to answer questions relating to Python or the class material. All questions relating to this Final should be directed to your instructor, and posted on Piazza. Posts on piazza should not contain any code. Only questions meant to clarify the exam are allowed. No debugging-related questions will be answered.
The deadline for the exam is Friday, May 8, at 4:00 p.m.' While you are given 8 days on this exam, the programming should not take you more than a day, two at most, so organize your time well. No extensions will be granted beyond the due date and time.