Difference between revisions of "CSC111 Homework 13 2014"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- <bluebox> This homework is a makeup homework. You have until Friday May 2nd, midnight to submit it. You can work in pair-programming on this assignment. </bluebo...")
 
(Question 1)
 
(23 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 14:54, 5 April 2014 (EDT)
 
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 14:54, 5 April 2014 (EDT)
 
----
 
----
 +
<br />
 +
<br />
 +
<center>
 +
=MAKE-UP ASSIGNMENT=
 +
</center>
 +
<br />
 +
<br />
 +
 +
{|
 +
|
 +
__TOC__
 +
|
 +
<br />
 
<bluebox>
 
<bluebox>
This homework is a makeup homework.  You have until Friday May 2nd, midnight to submit it.  You can work in pair-programming on this assignment.
+
This homework is a make-up assignment.  You have until '''Friday evening, May 2nd, midnight''' to submit it.  You can work in pair-programming on this assignment.
 
</bluebox>
 
</bluebox>
 +
|}
 +
<br />
 +
<br />
  
=Logistics=
+
=Logistics for Grading=
 
+
<br />
The algorithm used to incorporate this assignment in your overall grade is the following:
+
The algorithm used to incorporate this assignment in your overall final grade is the following:
  
 
<source lang="python">
 
<source lang="python">
Line 37: Line 53:
 
</source>
 
</source>
 
<br />
 
<br />
 +
 +
<br />
 +
 +
=Your Assignment=
 +
<br />
 +
* Download this file: [[Media:AllUKTemperatures.zip| AllUKTemperatures.zip]]
 +
* Save the file in a folder of your choosing
 +
* Unzip the zip file.  You should get 37 text files.  You should recognize two of them as files you have played with before.
 +
* Store this simple (undocumented) Python program in the same directory:
 +
 +
<br />
 +
<source lang="python">
 +
temp = [ ('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') ]
 +
 +
def getStats():
 +
    print( "    %20s: Number of lines" % "UK City" )
 +
    for i,pair in enumerate( temp ):
 +
        name = pair[0]
 +
        fileName = pair[1]
 +
        file = open( fileName, 'r' )
 +
        print( "%2d: %20s:  %5d lines" %
 +
              ( i+1, name, len( file.readlines() ) ) )
 +
        file.close()
 +
 +
def main():
 +
    getStats()
 +
 +
main()
 +
</source>
 +
* Run the program.  You should get an output of this form:
 +
<br />
 +
<source lang="text">
 +
                UK City: Number of lines
 +
1:            Aberporth:    876 lines
 +
2:              Armagh:  1932 lines
 +
3:  Ballypatrick Forest:    630 lines
 +
4:            Bradford:  1272 lines
 +
5:              Braemar:    660 lines
 +
6:            Camborne:    424 lines
 +
7:      Cambridge NIAB:    660 lines
 +
8:    Cardiff Bute Park:    436 lines
 +
9:            Chivenor:    696 lines
 +
10:          Cwmystwyth:    626 lines
 +
11:        Dunstaffnage:    511 lines
 +
12:              Durham:  1608 lines
 +
13:          Eastbourne:    660 lines
 +
14:          Eskdalemuir:  1236 lines
 +
15:            Heathrow:    792 lines
 +
16:                Hurn:    684 lines
 +
17:              Lerwick:    997 lines
 +
18:            Leuchars:    684 lines
 +
19:            Lowestoft:  1188 lines
 +
20:              Manston:    870 lines
 +
21:                Nairn:    996 lines
 +
22:          Newton Rigg:    660 lines
 +
23:              Oxford:  1932 lines
 +
24:              Paisley:    660 lines
 +
25:              Ringway:    714 lines
 +
26:          Ross-on-Wye:    997 lines
 +
27:            Shawbury:    816 lines
 +
28:            Sheffield:  1572 lines
 +
29:          Southampton:  1751 lines
 +
30:    Stornoway Airport:  1686 lines
 +
31:    Sutton Bonington:    660 lines
 +
32:                Tiree:  1032 lines
 +
33:              Valley:    997 lines
 +
34:          Waddington:    804 lines
 +
35:              Whitby:    628 lines
 +
36:        Wick Airport:  1200 lines
 +
37:            Yeovilton:    592 lines
 +
</source>
 +
<br />
 +
This program is just for you to have a seed of code to get started.  You do not need to use the function '''getStats()''' in your own program.
 +
<br />
 +
=Question 1=
 +
<br />
 +
Write a program called '''hw13a.py''' that will read these files (you can modify these original files for debugging, but your submitted program will be tested on copies of my originals) and output the city in the UK that got the most amount of rain in a given month.  Your program will ask the user for the year first,  and then for the month.  Here is an example
 +
 +
please enter year: <u>2010</u>
 +
please enter month: <u>12</u>
 +
 +
Your program should output
 +
# A title clearly indicating '''Question 1''' in it.
 +
# the city
 +
# the year
 +
# the month (expressed as January, February, ... December)
 +
# the amount of rain recorded
 +
<br />
 +
 +
=Question 2=
 +
<br />
 +
Make your program also output the city that experienced the biggest difference in tmax-tmin temperature since 2000, included.
 +
<br />
 +
Your program should output
 +
# A title clearly indicating '''Question 2''' in it.
 +
# the city
 +
# the year
 +
# the month (expressed as January, February, ... December)
 +
# the largest difference observed
 +
<br />
 +
 +
=Question 3=
 +
<br />
 +
Make your program output all the city names sorted by year when a temperature recording was first made for them.
 +
For example, the first temperature recording for Armagh was in 1865.  The first temperature recording for Sheffield was in 1883.  Therefore Armagh should be listed before Sheffield in your output.
 +
<br />
 +
Your program should output a title clearly indicating '''Question 3''' in it, followed by the list of cities in two columns, the first column containing the years, the second the city names.  The city names are all aligned, one above each other:
 +
 +
Question 3
 +
==========
 +
Year  City
 +
...
 +
1865  Armagh
 +
...
 +
1883  Sheffield
 +
...
 +
 +
<br />
 +
 +
=Grading=
 +
<br />
 +
* Documentation, style, and readability: 20 points
 +
* Organization into functions, passing of parameters: 20 points
 +
* Correct output: 20+20+20 points
 +
<br />
 +
 +
=Submission=
 +
<br />
 +
Submit your program to this URL: [http://cs.smith.edu/~thiebaut/111b/submit13.php http://cs.smith.edu/~thiebaut/111b/submit13.php]

Latest revision as of 17:02, 2 December 2015

--D. Thiebaut (talk) 14:54, 5 April 2014 (EDT)




MAKE-UP ASSIGNMENT




This homework is a make-up assignment. You have until Friday evening, May 2nd, midnight to submit it. You can work in pair-programming on this assignment.



Logistics for Grading


The algorithm used to incorporate this assignment in your overall final grade is the following:

  # hw13 is the makeup assignment.
  
  if  youDoThisMakeupAssignment():
      hw13 = # your grade on this assignment
  else:
      hw13 = 0

  # create a list of all your homework assignment grades.  homework assignments missed get a 0
  homeworkGrades = [ hw1, hw2, hw3, hw4, hw5, hw6, hw7, hw8, hw9, hw10, hw11, hw12 ]

  # find the lowest grade
  minHW = min( homeworkGrades )

  # find where the lowest grade is
  minIndex = homeworkGrades.index( minHW )

  # replace lowest with grade of hw13 if this one is greater
  if hw13 > minHW:
      L[ minIndex ] = hw13

  # Drop the lowest assignment of the semester
  minHW = min( homeworkGrades )
  minIndex = homeworkGrades.index( minHW )
  homeworkGrades.pop( minIndex )



Your Assignment


  • Download this file: AllUKTemperatures.zip
  • Save the file in a folder of your choosing
  • Unzip the zip file. You should get 37 text files. You should recognize two of them as files you have played with before.
  • Store this simple (undocumented) Python program in the same directory:


temp = [ ('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') ]

def getStats():
    print( "    %20s: Number of lines" % "UK City" )
    for i,pair in enumerate( temp ):
        name = pair[0]
        fileName = pair[1]
        file = open( fileName, 'r' )
        print( "%2d: %20s:  %5d lines" %
               ( i+1, name, len( file.readlines() ) ) )
        file.close()

def main():
    getStats()

main()
  • Run the program. You should get an output of this form:


                 UK City: Number of lines
 1:            Aberporth:    876 lines
 2:               Armagh:   1932 lines
 3:  Ballypatrick Forest:    630 lines
 4:             Bradford:   1272 lines
 5:              Braemar:    660 lines
 6:             Camborne:    424 lines
 7:       Cambridge NIAB:    660 lines
 8:    Cardiff Bute Park:    436 lines
 9:             Chivenor:    696 lines
10:           Cwmystwyth:    626 lines
11:         Dunstaffnage:    511 lines
12:               Durham:   1608 lines
13:           Eastbourne:    660 lines
14:          Eskdalemuir:   1236 lines
15:             Heathrow:    792 lines
16:                 Hurn:    684 lines
17:              Lerwick:    997 lines
18:             Leuchars:    684 lines
19:            Lowestoft:   1188 lines
20:              Manston:    870 lines
21:                Nairn:    996 lines
22:          Newton Rigg:    660 lines
23:               Oxford:   1932 lines
24:              Paisley:    660 lines
25:              Ringway:    714 lines
26:          Ross-on-Wye:    997 lines
27:             Shawbury:    816 lines
28:            Sheffield:   1572 lines
29:          Southampton:   1751 lines
30:    Stornoway Airport:   1686 lines
31:     Sutton Bonington:    660 lines
32:                Tiree:   1032 lines
33:               Valley:    997 lines
34:           Waddington:    804 lines
35:               Whitby:    628 lines
36:         Wick Airport:   1200 lines
37:            Yeovilton:    592 lines


This program is just for you to have a seed of code to get started. You do not need to use the function getStats() in your own program.

Question 1


Write a program called hw13a.py that will read these files (you can modify these original files for debugging, but your submitted program will be tested on copies of my originals) and output the city in the UK that got the most amount of rain in a given month. Your program will ask the user for the year first, and then for the month. Here is an example

please enter year: 2010
please enter month: 12

Your program should output

  1. A title clearly indicating Question 1 in it.
  2. the city
  3. the year
  4. the month (expressed as January, February, ... December)
  5. the amount of rain recorded


Question 2


Make your program also output the city that experienced the biggest difference in tmax-tmin temperature since 2000, included.
Your program should output

  1. A title clearly indicating Question 2 in it.
  2. the city
  3. the year
  4. the month (expressed as January, February, ... December)
  5. the largest difference observed


Question 3


Make your program output all the city names sorted by year when a temperature recording was first made for them. For example, the first temperature recording for Armagh was in 1865. The first temperature recording for Sheffield was in 1883. Therefore Armagh should be listed before Sheffield in your output.
Your program should output a title clearly indicating Question 3 in it, followed by the list of cities in two columns, the first column containing the years, the second the city names. The city names are all aligned, one above each other:

Question 3
==========
Year  City
...
1865  Armagh
...
1883  Sheffield
...


Grading


  • Documentation, style, and readability: 20 points
  • Organization into functions, passing of parameters: 20 points
  • Correct output: 20+20+20 points


Submission


Submit your program to this URL: http://cs.smith.edu/~thiebaut/111b/submit13.php