CSC111 Homework 11 2015

From dftwiki3
Revision as of 17:02, 12 April 2015 by Thiebaut (talk | contribs)
Jump to: navigation, search

--D. Thiebaut (talk) 17:20, 12 April 2015 (EDT)


<showafterdate after="20150415 12:00" before="20150601 00:00">


This Homework is due on 4/21/15 at 11:55 p.m.


Problem #1: Temperatures in the UK

HistoricStationDataUKWeather.png


Assignment

  • Your assignment is to write a program that reads weather data from a text file, then processes the data, and finally outputs the answers to several questions.
  • Call your program hw11_1.py

The Text Files and Their Format


  • The British government has been keeping track of temperatures in several cities of the U.K. The official Web site where the data is available is http://www.metoffice.gov.uk/climate/uk/stationdata/. The records of temperatures for 37 towns/cities of the UK for the past few years, going back in some cases to 1853, are kept on this site.


  • The data recorded consists of these quantities
  • Mean daily maximum temperature (tmax)
  • Mean daily minimum temperature (tmin)
  • Days of air frost (af)
  • Total rainfall (rain)
  • Total sunshine duration (sun)
(More information can be found here.)


  • The format for the data is CSV.
  • The data from the UK Web site have been mirrored on a Smith server: http://cs.smith.edu/~dthiebaut/UKTemperatures/. You will need to download a few files from that site to develop and test your program.
  • The name of a file is simply the name of the U.K. town, all lowercase, suffixed by "data.txt."


Format of the data


  • Download one of the files from http://cs.smith.edu/~dthiebaut/UKTemperatures/, say armaghdata.txt, and take a look at it. Use Notepad, TextEdit or your favorite text editor.
  • You will notice that when measurements are missing, they are replaced by "---". Your program should not skip measurements that are missing.
  • Sometimes, especially at the end of the file, measurements are suffixed with an asterisk (*). Your program should discard the asterisk, and treat the data as valid.
  • Some lines have the word "Provisional" at the end. Your program should treat these lines the same as regular line, and should not skip them.


Input


  • Your program should prompt the user for a file name. The user will supply the name of one of the text files that will have been previously downloaded from the Smith Web site listed above. In other words, your program simply needs to read a text file and does not need to access the Web.
  • If the user provides an invalid file name, your program will keep on prompting the user for a new name. Your program will only exit once it has been given a valid file name, and processed its data and output the answers.


Processing


  • You must use the method illustrated in the first 2 problems of Lab 11 to process the data.
  • All temperatures should be reported in degrees Celsius which is the system used in the U.K.


Questions


Question 1
In what year or years was the coldest temperature recorded? If the coldest temperature appears several times, list all the years and month in which it will have been reported. The format of the output is illustrated in a later section.


Question 2
In what year or years was the warmest temperature recorded? If the warmest temperature appears several times, list all the years and month in which it will have been reported. The format of the output is illustrated in a later section.
Question 3
What are the 5 sunniest months and years for the given city? The format of the output is illustrated below.


Output Format


  • Here is the expected output for armaghdata.txt:


> armagh.txt
Invalid file name, please re-enter
> armaghdata.txt
1, -4.2, 1878, 12, 1895, 2
2, 23.8, 1995, 8, 1989, 7
3, 256.0, 1940, 6, 252.9, 1949, 6, 251.6, 1935, 5, 244.1, 1957, 6, 243.8, 1989, 7


and here is the expected output for ballpatrickdata.txt:
> ballypatrickdata.txt
1, -1.8, 1979, 1
2, 20.0, 1995, 8
3, 279.3, 1975, 5, 272.6, 1976, 8, 253.7, 1977, 5, 247.2, 1984, 5, 245.6, 1974, 4

Note that each line is prefixed with a number, identifying the question for which the line is the answer.
Note, also, that the output is in CSV form. A coma separates all the values. No extra spaces should appear in front of comas.

Moodle Submission

  • Submit your program in the Moodle HW11 PB1 section.


</showafterdate>