CSC111 Final Exam 2011
Final Exam
This exam is given under the rules of the honor code at Smith College. It is open-books, open-notes, and open-Web. The work on this exam is to be done individually, and assistance from anybody other than the instructor is forbidden. TAs are not available to answer questions, and will be asked not to do so. Pair-programming is not allowed.
Any program section greater than a function used and taken from a Web site other than our CSC111 Web page should be cited in the header of your program, or the header of the function.
Questions can only be asked to your instructor, and only via email. Email questions will be returned with an answer to the whole class.
The exam is due on 12/22/11 at 4:00 p.m. Any file received after this date will not be graded. You will need to submit the exam using the rsubmit command, or using a submit Web page, similarly to the way you have submitted homework assignments this past semester. If you are having problem with either one of these submission options, email your file(s) to me before the deadline, at dthiebau@smith.edu.
Important Note: The lab of 12/15/11 will count for 1/3 point of this exam. You will need to demonstrate that you have code one of the last two challenges of the lab to get the points. You can work in pair during the lab, but not for the programming part which is explained below.
Problem Selection
- You have the choice between two problems.
- One deals with graphics. One deals with Web pages and parsing text.
- Study both problems well, then decide which one you want to pick.
Problem #1: Temperatures in the UK
You have to write a program that reads weather data from the Web, process the data, and output the answers to several questions.
- Please call your program final1.py
The Web site http://www.metoffice.gov.uk/climate/uk/stationdata/ keeps records of temperatures for 37 towns/cities of the UK for the past few years, going back in some cases to 1853.
Your assignment requires you to write a program that will read the data from this site, for all the cities, gather some statistics, and output information in a nice, human readable format.
Accessing the Data
- The main address for the data is that of the Met-Office site: http://www.metoffice.gov.uk/climate/uk/stationdata/
- Note: in case the metoffice.gov.uk were to go down during the exam period, the data has been replicated at http://cs.smith.edu/~111a/climate/uk/stationdata/, and you can use this Smith-based Url instead. The data files are the same at both places.
- A file name is associated with each city or town. For example, the city of Aberporth is associated with aberporthdata.txt, and the record of the weather data for Aberporth is stored at URL http://www.metoffice.gov.uk/climate/uk/stationdata/aberporthdata.txt
- All cities have the same style of URL to access the data for them.
- The list of all the town names and their associated file names is given to you below.
Town/City | File Name | Year |
---|---|---|
Aberporth | aberporthdata.txt | 1941 |
Armagh | armaghdata.txt | 1853 |
Ballypatrick Forest | ballypatrickdata.txt | 1961 |
Bradford | bradforddata.txt | 1908 |
Braemar | braemardata.txt | 1959 |
Camborne | cambornedata.txt | 1978 |
Cambridge NIAB | cambridgedata.txt | 1959 |
Cardiff Bute Park | cardiffdata.txt | 1977 |
Chivenor | chivenordata.txt | 1951 |
Cwmystwyth | cwmystwythdata.txt | 1959 |
Dunstaffnage | dunstaffnagedata.txt | 1972 |
Durham | durhamdata.txt | 1880 |
Eastbourne | eastbournedata.txt | 1959 |
Eskdalemuir | eskdalemuirdata.txt | 1914 |
Heathrow | heathrowdata.txt | 1948 |
Hurn | hurndata.txt | 1957 |
Lerwick | lerwickdata.txt | 1930 |
Leuchars | leucharsdata.txt | 1957 |
Lowestoft | lowestoftdata.txt | 1914 |
Manston | manstondata.txt | 1934 |
Nairn | nairndata.txt | 1931 |
Newton Rigg | newtonriggdata.txt | 1959 |
Oxford | oxforddata.txt | 1853 |
Paisley | paisleydata.txt | 1959 |
Ringway | ringwaydata.txt | 1946-2004 |
Ross-on-Wye | rossonwyedata.txt | 1930 |
Shawbury | shawburydata.txt | 1946 |
Sheffield | sheffielddata.txt | 1883 |
Southampton | southamptondata.txt | 1855-2000 |
Stornoway Airport | stornowaydata.txt | 1873 |
Sutton Bonington | suttonboningtondata.txt | 1959 |
Tiree | tireedata.txt | 1928 |
Valley | valleydata.txt | 1930 |
Waddington | waddingtondata.txt | 1947 |
Whitby | whitbydata.txt | 1961 |
Wick Airport | wickairportdata.txt | 1914 |
Yeovilton | yeoviltondata.txt | 1964 |
The contents of this table is available to you as a Python list for your convenience:
[ ('Aberporth', 'aberporthdata.txt'), ('Armagh', 'armaghdata.txt'), ('Ballypatrick Forest', 'ballypatrickdata.txt'), ('Bradford', 'bradforddata.txt'), ('Braemar', 'braemardata.txt'), ('Camborne', 'cambornedata.txt'), ('Cambridge NIAB', 'cambridgedata.txt'), ('Cardiff Bute Park', 'cardiffdata.txt'), ('Chivenor', 'chivenordata.txt'), ('Cwmystwyth', 'cwmystwythdata.txt'), ('Dunstaffnage', 'dunstaffnagedata.txt'), ('Durham', 'durhamdata.txt'), ('Eastbourne', 'eastbournedata.txt'), ('Eskdalemuir', 'eskdalemuirdata.txt'), ('Heathrow', 'heathrowdata.txt'), ('Hurn', 'hurndata.txt'), ('Lerwick', 'lerwickdata.txt'), ('Leuchars', 'leucharsdata.txt'), ('Lowestoft', 'lowestoftdata.txt'), ('Manston', 'manstondata.txt'), ('Nairn', 'nairndata.txt'), ('Newton Rigg', 'newtonriggdata.txt'), ('Oxford', 'oxforddata.txt'), ('Paisley', 'paisleydata.txt'), ('Ringway', 'ringwaydata.txt'), ('Ross-on-Wye', 'rossonwyedata.txt'), ('Shawbury', 'shawburydata.txt'), ('Sheffield', 'sheffielddata.txt'), ('Southampton', 'southamptondata.txt'), ('Stornoway Airport', 'stornowaydata.txt'), ('Sutton Bonington', 'suttonboningtondata.txt'), ('Tiree', 'tireedata.txt'), ('Valley', 'valleydata.txt'), ('Waddington', 'waddingtondata.txt'), ('Whitby', 'whitbydata.txt'), ('Wick Airport', 'wickairportdata.txt'), ('Yeovilton', 'yeoviltondata.txt') ]
Test
- here is a simple program for accessing the list of towns and files from the beowulf page (this won't get the data for a given town, but simply illustrates how to get some related information from the Smith Web site.)
import urllib.request
import sys
BASEURL = "http://cs.smith.edu/~111a/climate/uk/stationdata/"
def getMainList( url ):
#print( "Getting list from ", url )
f = urllib.request.urlopen( url )
bytes = f.read()
htmlText = bytes.decode( "utf8" )
return htmlText
def main():
global BASEURL
text = getMainList( BASEURL )
print( text )
main()
Format of the data
- The format of the data is explained at http://www.metoffice.gov.uk/climate/uk/stationdata/, a copy of which is available here.
- Your program should accept estimated data as well as real data. In other words, data followed by an asterisk should not be dropped or skipped.
Processing
- You are free to choose the way you are going to process the data, but if you want extra-credits, you need to define and use one or several classes.
Questions needing answers
- Your program should output formatted answers to the questions listed below. By formatted, I mean something written in English and not in Python ("The coldest years were 1914 and 1931" is formatted. "[1914, 1931]" is not formatted.)
- Your program should print "Answer to Question 1", "Answer to Question 2", etc. for each question.
- All temperatures should be reported in degrees Fahrenheit (they are all in Celcius on the original Web site).
- Question 1
- For which town (or towns) do we have the oldest recorded information? Although we can get the answer by searching the table above, make your program figure out the answer. If two or more towns have records for the same month and year, and these are the oldest on record, then output the name of each town.
- The output should be of the form: "the oldest observation was recorded in townname in month of year"
- Question 2
- For which town or towns do we have the lowest temperature recorded? Also output the month and year of the measurement.
- The output should be of the form: the coldest temperature was recorded in townname in month of year" where month is either Jan, Feb, Mar, Apr... Dec. Numbers are not acceptable. If the month is not specified in the file, then simply output the year.
- Question 3
- For which town or towns do we have the highest temperature recorded? Also output the month and year of the observation.
- Same output format as for Question 2
- Question 4
- For which town do we have the biggest yearly difference in temperature? In other words, where did we record the largest difference between coldest and hottest temperature in a given year?
- Same output format type as for Question 2.
- Question 5
- If we are interested in retiring in the U.K., and are looking for the place with the most sun exposure per year, which city should be picked? Make sure you document your program well and explain how you compute the answer.
- Question 6
- Was the average temperature in the U.K. colder during the first half of the 20th century (1900 to 1999), or hotter?
- Make sure your program prints out all the data required to support your answer, all in a readable format.
Documentation
- Document your program!
- Document your program!
- Document your program!
- The solution programs for past homework assignments are good examples of fine documentation.
- A significant portion of the final grade will be for the clarity of the documentation.
Submission
rsubmit final final1.py
- or use this submit page: http://cs.smith.edu/~111a/submitFinal.htm
- Reminder: Programs submitted after 4:00 p.m. on the due date will not be graded. Also, if you submit a program before the due date, and submit it again after the due date, the date recorded will be the later one, and hence your program will not be graded in this case.
Extra-Credits
- 1/2 extra point if you define classes and use objects instantiated from these classes.
Advice
- A program that runs is worth more than one that doesn't.
- Even if the one that doesn't run attempts to answer all the questions.
- Start small!
- If it makes life easier for you to make your program read the temperature data from a file or from a string rather than from the Web, then use this approach first while you are developing the code. You can switch at the end to making your program read information from the Web.
- Concentrate on the easy questions first.
- There is nothing sacred about the order in which the questions above are ordered. The order in which the program outputs the results is important, though.
- Submit regularly.
- Whenever you have a version of your program that works, just submit it. Every submission overwrites the previous version submitted.
- Be resourceful.
- There won't be any extension due to failure of the computer, either beowulf or yours. Python can run on all the various platforms available to you. As long as the computer you are using can access the Web, you can write a program for the final. In case beowulf is down on the last day of exam period, email your program to me (dthiebau@smith.edu) before the 4:00 p.m. deadline.
Problem #2
- For this problem you have to write a graphics program showing an aquarium and fish swimming in it.
Requirements
Behavior
- When the program starts, the aquarium should be fully empty.
- Bubbles will start rising from time to time (randomly) from the bottom of the tank, up to the surface. Bubbles are simply white circles that climb up, with random horizontal movements as they climb (see image below).
- When the user clicks the mouse on the aquarium (anywhere on the graphics image), the program displays two different fish, randomly picked from a collection (at least 3) of fish maintained by your program. The fish are immobile and the user clicks on the one she wants to keep in the aquarium. As soon as she has done so, the selected fish reappears at some other point of the aquarium and starts swimming.
- Fish swim in a forward direction, i.e. toward the direction where their nose is pointing.
- When fish disappear on one side of the screen, they do not wrap around but reappear swimming from the exact place where they disappeared, but this time swimming in the opposite direction. You will need a reverse image of the fish when it swims in the opposite direction. See this page for samples of fish images and reverse images.
- Every so often fish will emit a bubble from their mouth. This bubble, like the bubbles coming from the sand at the bottom of the tank, climb up to the surface with slight horizontal movements as they move.
- Bubbles should start small, with a radius of, say, 2 or 3 pixels, and grow slightly bigger as they climb up to the surface.
Getting fish and images
- You can get the fish and the tank images from this page
- Note 1
- the fishxxr.gif is the reverse image of fishxx.gif, for all xx numbers.
Programming
- You must divide your program into two files. The classes should be in one file called final2class.py, and the main program should be called final2.py.
- You must use classes to represent the fish, the bubbles, and the school of fish. Bubbles should be represented as two circles, one with a white border, transparent, and the other one, smaller, inside the previous one, and white, as illustrated below:
- When bubble expands, as they rise, it's okay to change only the larger of the two circles.
Submission
- Submit all your files (including the class file, and the gif images for the tank and fish) using the rsubmit command on beowulf:
rsubmit final final2.py rsubmit final final2class.py rsubmit final Tank2.gif rsubmit final fish14.gif rsubmit final fish14r.gif etc...
- or use the http://cs.smith.edu/~111a/submitFinal.htm form. Note: only gif files are accepted for images.
Advice and Documentation
- Same advice as for Problem #1!
- Good luck!