Difference between revisions of "CSC111 Programs for Week 11 2015"
(→processEmails.py) |
|||
Line 964: | Line 964: | ||
</source> | </source> | ||
<br /> | <br /> | ||
+ | =inheritance1.py= | ||
<br /> | <br /> | ||
+ | This program simply displays a car with a body and 2 wheels. The Car class will become the '''super class''' for new derived classes. | ||
+ | <br /> | ||
+ | ::<source lang="python"> | ||
+ | from graphics import * | ||
+ | |||
+ | WIDTH = 600 | ||
+ | HEIGHT = 400 | ||
+ | |||
+ | class Wheel: | ||
+ | """a Wheel is 2 concentric circles, the larger one black, | ||
+ | the smaller one grey.""" | ||
+ | |||
+ | def __init__(self, centr, rad1, rad2 ): | ||
+ | # make circ1 the smaller of the 2 circles | ||
+ | self.circ1 = Circle( centr, min( rad1, rad2 ) ) | ||
+ | self.circ2 = Circle( centr, max( rad1, rad2 ) ) | ||
+ | self.circ1.setFill( "grey" ) | ||
+ | self.circ2.setFill( "black" ) | ||
+ | |||
+ | def draw( self, win ): | ||
+ | self.circ2.draw( win ) | ||
+ | self.circ1.draw( win ) | ||
+ | |||
+ | def move( self, dx, dy ): | ||
+ | self.circ2.move( dx, dy ) | ||
+ | self.circ1.move( dx, dy ) | ||
+ | |||
+ | class Car: | ||
+ | """A default simple car class. Sets the color to "Yellow" """ | ||
+ | def __init__( self, rp ): | ||
+ | x = rp.getX() | ||
+ | y = rp.getY() | ||
+ | length = 180 | ||
+ | height = length // 3 | ||
+ | firstQuarter = length//4 | ||
+ | thirdQuarter = length * 3 // 4 | ||
+ | p2 = Point( x+length, y+height ) | ||
+ | self.body = Rectangle( rp, p2 ) | ||
+ | self.body.setFill( "yellow" ) | ||
+ | self.w1 = Wheel( Point( x+firstQuarter, y+height ), 20,10 ) | ||
+ | self.w2 = Wheel( Point( x+thirdQuarter, y+height ), 20,10 ) | ||
+ | |||
+ | def draw( self, win ): | ||
+ | self.body.draw( win ) | ||
+ | self.w1.draw( win ) | ||
+ | self.w2.draw( win ) | ||
+ | |||
+ | def move( self, dx, dy ): | ||
+ | self.body.move( dx, dy ) | ||
+ | self.w1.move( dx, dy ) | ||
+ | self.w2.move( dx, dy ) | ||
+ | |||
+ | def main(): | ||
+ | # open the window | ||
+ | win = GraphWin( "CSC111 Inheritance Demo", WIDTH, HEIGHT ) | ||
+ | |||
+ | car = Car( Point( 100,250 ) ) | ||
+ | car.draw( win ) | ||
+ | |||
+ | win.getMouse() | ||
+ | win.close() | ||
+ | |||
+ | main() | ||
+ | </source> | ||
<br /> | <br /> | ||
<br /> | <br /> |
Revision as of 11:08, 14 April 2015
--D. Thiebaut (talk) 12:50, 13 April 2015 (EDT)
Contents
Aqarium.py (with bubbles)
# aquarium.gif
# D. Thiebaut
# This is a variation on the program seen during Week 10. This time we have a collection of
# bubbles that appear wherever the user clicks the mouse.
#
from graphics import *
import random
WIDTH = 700 # geometry of tank2.gif
HEIGHT = 517
class Fish:
def __init__( self, fileNm, xx, yy ):
self.fileName = fileNm
self.x = xx
self.y = yy
self.image = Image( Point( xx, yy ), fileNm )
def draw( self, win ):
self.image.draw( win )
def moveRandom( self ):
deltax = - random.randrange( 10 )
deltay = random.randrange( -3, 3 )
self.image.move( deltax, deltay )
x = self.image.getAnchor().getX()
if x < -50:
self.image.move( WIDTH+100, 0 )
class Bubble:
def __init__( self, center ):
self.circ = Circle( center, random.randrange(5, 15) )
self.circ.setOutline( "white" )
def draw( self, win ):
self.circ.draw( win )
def moveRandom( self ):
deltaX = random.randrange( -3, 3 )
deltaY = random.randrange( -5, 0 )
self.circ.move( deltaX, deltaY )
# make bubbles wrap around...
if self.circ.getCenter().getY() < 0:
self.circ.move( 0, HEIGHT+50 )
def main():
# open the window
win = GraphWin( "CSC Aquarium", WIDTH, HEIGHT )
# display background
background = Image( Point( WIDTH//2, HEIGHT//2 ), "tank2.gif" )
background.draw( win )
fishList = []
for i in range( 4 ):
fish = Fish( "fish0.gif", i*100, 350 )
fish.draw( win )
fishList.append( fish )
# animation loop
bubbles = []
while True:
# move all fish
for fish in fishList:
fish.moveRandom()
# new bubble?
p = win.checkMouse() # did the user click the mouse?
if p != None: # None means no, a real Point means yes
b = Bubble( p ) # create a new bubble
b.draw( win ) # draw it
bubbles.append( b ) # add it to the list of bubbles
# move bubbles
for b in bubbles:
b.moveRandom()
win.close()
main()
Rainy Cambridge, U.K.
# rainyCambridge.py
# D. Thiebaut
# Given the contents of a text file containing the data for
# the weather measured in Cambridge, U.K., report the 10 rainiest days
# on record.
# The original data is kept on this site:
# http://www.metoffice.gov.uk/pub/data/weather/uk/climate/stationdata/cambridgedata.txt
text="""Cambridge NIAB
Location: 5435E 2606N, 26 metres amsl
Estimated data is marked with a * after the value.
Missing data (more than 2 days missing in month) is marked by ---.
Sunshine data taken from an automatic Kipp & Zonen sensor marked with a #, otherwise sunshine data taken from a Campbell Stokes recorder.
yyyy mm tmax tmin af rain sun
degC degC days mm hours
1959 1 4.4 -1.4 20 --- 78.1
1959 2 7.5 1.2 9 --- 66.0
1959 3 11.5 3.8 0 --- 98.0
1959 4 14.3 5.4 0 --- 146.1
1959 5 18.1 6.5 0 --- 224.8
1959 6 21.6 10.1 0 --- 252.4
1959 7 23.9 12.2 0 --- 270.7
1959 8 23.5 13.0 0 --- 213.4
1959 9 21.7 9.0 0 --- 171.3
1959 10 18.0 7.5 0 --- 167.6
1959 11 10.2 3.2 6 --- 59.9
1959 12 8.7 3.2 2 --- 36.7
1960 1 6.7 1.6 12 --- 36.3
1960 2 7.5 1.4 9 --- 72.7
1960 3 9.7 2.9 5 --- 61.6
1960 4 14.0 4.5 2 --- 162.7
1960 5 18.5 8.2 0 --- 202.6
1960 6 21.7 10.4 0 --- 260.2
1960 7 20.1 11.4 0 --- 154.7
1960 8 20.6 10.9 0 --- 159.8
1960 9 17.7 9.5 0 --- 125.0
1960 10 14.0 7.6 0 --- 71.8
1960 11 10.6 4.6 0 --- 65.4
1960 12 6.5 2.1 5 --- 48.6
1961 1 6.2 1.0 5 55.9 50.5
1961 2 10.3 4.3 0 50.4 65.9
1961 3 13.7 3.3 1 5.2 170.4
1961 4 14.9 6.2 0 44.5 101.0
1961 5 16.4 6.4 0 23.6 218.4
1961 6 21.4 9.8 0 32.7 243.2
1961 7 20.9 11.3 0 32.8 185.6
1961 8 21.3 11.6 0 50.3 182.6
1961 9 20.4 11.5 0 63.8 131.1
1961 10 15.3 7.3 0 57.8 141.4
1961 11 9.4 2.9 6 41.5 72.7
1961 12 5.5 -0.6 18 79.7 58.3
1962 1 7.3 0.7 9 62.3 73.5
1962 2 7.6 1.2 9 11.4 79.3
1962 3 6.8 -1.4 17 26.5 102.4
1962 4 12.3 4.1 1 38.8 139.5
1962 5 14.5 6.6 1 45.9 160.1
1962 6 19.6 8.0 0 0.5 289.6
1962 7 19.4 11.0 0 56.0 126.4
1962 8 19.9 11.0 0 55.1 182.1
1962 9 17.5 8.9 0 73.6 129.6
1962 10 14.9 6.5 1 32.5 104.4
1962 11 8.2 2.6 8 35.5 34.2
1962 12 4.6 -2.5 18 33.7 68.6
1963 1 -0.1 -5.7 29 24.7 58.0
1963 2 1.2 -3.5 27 13.2 59.0
1963 3 9.9 2.8 7 50.3 102.6
1963 4 13.4 4.7 3 41.0 124.9
1963 5 15.8 6.3 0 43.5 189.5
1963 6 20.6 10.0 0 43.0 201.8
1963 7 20.6 10.6 0 52.4 170.1
1963 8 19.0 10.6 0 100.4 119.6
1963 9 17.9 9.3 0 44.1 134.0
1963 10 14.3 8.0 0 48.6 78.4
1963 11 11.4 5.2 1 78.6 52.8
1963 12 5.0 -0.7 20 11.1 48.7
1964 1 5.0 -0.3 15 18.7 45.8
1964 2 7.4 1.8 8 16.6 70.8
1964 3 6.7 1.5 10 76.2 52.4
1964 4 12.9 5.1 2 59.1 113.9
1964 5 19.6 8.7 0 21.5 208.5
1964 6 18.7 10.4 0 94.7 150.7
1964 7 22.2 12.2 0 40.2 198.0
1964 8 21.6 11.5 0 21.8 200.2
1964 9 20.5 8.9 0 12.1 196.1
1964 10 13.3 4.6 0 27.1 114.2
1964 11 10.5 4.0 6 34.8 63.0
1964 12 6.5 0.1 17 37.3 48.7
1965 1 6.1 0.9 16 47.4 78.3
1965 2 5.6 0.6 10 15.1 29.1
1965 3 10.0 1.1 11 51.8 125.0
1965 4 12.9 4.2 2 42.4 122.2
1965 5 16.5 7.8 0 47.8 166.2
1965 6 19.2 9.7 0 43.2 174.8
1965 7 18.3 10.4 0 63.6 103.4
1965 8 20.3 10.2 0 65.4 174.0
1965 9 17.5 8.8 0 85.6 127.0
1965 10 15.4 6.1 2 14.8 115.1
1965 11 8.0 1.6 14 36.9 86.5
1965 12 7.3 1.4 8 81.7 52.0
1966 1 4.6 0.4 16 29.6 34.0
1966 2 8.8 3.3 8 56.7 43.6
1966 3 10.8 2.6 7 8.5 115.9
1966 4 11.6 4.5 2 65.4 82.2
1966 5 16.7 6.5 0 35.8 196.7
1966 6 21.5 10.8 0 56.9 181.6
1966 7 19.5 11.1 0 70.4 145.5
1966 8 20.4 10.6 0 75.0 186.6
1966 9 19.0 10.1 0 35.0 148.3
1966 10 14.4 7.6 0 64.7 74.9
1966 11 8.3 2.7 5 39.9 52.2
1966 12 8.4 2.0 7 69.6 39.9
1967 1 7.1 2.0 8 21.8 71.9
1967 2 8.9 2.0 7 34.7 88.3
1967 3 11.7 4.0 0 18.9 188.3
1967 4 12.0 4.0 3 53.1 134.7*
1967 5 15.5 6.9 1 118.0 178.6
1967 6 19.5 9.2 0 29.7 213.6
1967 7 23.3 12.9 0 61.4 211.0
1967 8 21.4 11.6 0 22.1 152.8
1967 9 18.1 10.0 0 39.1 110.3
1967 10 14.6 8.2 0 107.1 94.9
1967 11 8.6 2.2 8 44.9 59.4
1967 12 6.4 1.0 13 40.8 65.4
1968 1 6.8 0.9 13 37.2 38.2
1968 2 4.8 -0.5 19 17.2 40.5
1968 3 11.1 2.9 5 10.1 130.8
1968 4 13.6 3.7 8 36.8 172.0
1968 5 15.0 6.0 0 32.7 149.4
1968 6 20.1 10.3 0 75.9 172.4
1968 7 19.5 11.3 0 83.5 127.6
1968 8 19.6 11.7 0 93.8 120.8
1968 9 18.4 10.7 0 85.7 118.8
1968 10 16.1 10.1 0 42.1 64.0
1968 11 9.0 4.3 5 30.9 28.7
1968 12 4.8 0.8 10 39.8 18.8
1969 1 8.4 3.4 6 58.9 36.1
1969 2 3.5 -1.6 16 41.9 76.3
1969 3 6.6 0.8 6 53.9 66.4
1969 4 13.1 2.8 6 32.0 190.0
1969 5 16.4 8.0 0 90.7 166.0
1969 6 19.4 8.6 0 30.3 268.7
1969 7 22.9 12.5 0 44.1 213.9
1969 8 21.0 12.0 0 59.6 119.8
1969 9 18.8 10.6 1 2.4 123.4
1969 10 17.8 9.1 0 4.6 100.0
1969 11 8.9 2.7 5 64.3 64.0
1969 12 5.3 0.7 12 49.8 19.2
1970 1 6.3 1.4 10 52.4 30.3
1970 2 6.3 0.1 11 55.9 112.9
1970 3 7.1 -0.5 16 32.3 109.0
1970 4 10.8 3.2 5 66.4 125.4
1970 5 18.6 8.4 0 19.6 213.3
1970 6 22.5 10.7 0 96.5 264.8
1970 7 20.4 11.5 0 33.1 184.3
1970 8 21.5 11.1 0 33.2 181.0
1970 9 19.9 10.6 0 44.2 161.3
1970 10 15.5 7.3 0 20.3 105.8
1970 11 11.0* 4.9 2 117.8 60.0
1970 12 6.6 1.5 12 34.6 37.8
1971 1 7.1 2.0 9 71.6 39.6
1971 2 7.9 1.5 7 11.8 76.6
1971 3 8.4 1.6 9 41.2 101.8
1971 4 11.5 4.0 2 30.3 119.6
1971 5 17.2 6.3 2 51.9 239.8
1971 6 16.9 9.1 0 96.4 131.0
1971 7 22.5 12.2 0 16.3 238.3
1971 8 20.8 12.2 0 57.4 147.2
1971 9 20.1 8.5 0 21.4 173.1
1971 10 16.5 5.7 1 65.0 150.4
1971 11 9.5 1.7 11 61.9 96.4
1971 12 8.9 3.7 2 17.0 39.5
1972 1 6.0 1.6 8 46.0 48.6
1972 2 7.5 1.6 5 32.7 46.1
1972 3 11.8 2.0 5 42.1 150.0
1972 4 12.1 5.1 0 43.9 136.1
1972 5 15.7 6.8 0 26.0 205.2
1972 6 17.4 8.1 0 22.7 190.0
1972 7 20.9 11.4 0 26.8 167.0
1972 8 20.8 10.9 0 37.6 189.1
1972 9 16.4 8.1 0 29.9 121.4
1972 10 15.3 6.5 1 7.8 108.1
1972 11 9.6 3.2 7 48.9 83.3
1972 12 8.6 2.6 2 39.0 49.8
1973 1 6.9 1.8 8 14.8 39.7
1973 2 7.8 0.9 11 19.8 88.5
1973 3 11.1 2.0 4 10.4 134.4
1973 4 12.0 3.2 3 42.5 166.0
1973 5 16.7 7.2 0 66.5 200.8
1973 6 21.2 9.7 0 60.6* 273.1
1973 7 20.9 11.5 0 36.4 165.5
1973 8 23.1 11.9 0 18.4 198.1
1973 9 20.1 10.2 0 57.5 170.5
1973 10 13.3 5.2 2 25.9 110.4
1973 11 9.5 1.7 10 30.1 104.9
1973 12 8.0 1.8 8 29.5 57.3
1974 1 9.2* 2.7 3 46.2 66.4
1974 2 8.6 2.7 5 47.7 73.7
1974 3 9.6 2.6 3 16.2 100.8
1974 4 13.4 2.9 3 10.3 152.8
1974 5 16.2 6.1 0 22.3 226.0
1974 6 19.3 9.5 0 52.8 209.3
1974 7 20.1 11.1 0 29.1 215.3
1974 8 20.8 11.0 0 89.9 206.4
1974 9 16.9 8.7 0 71.2 171.4
1974 10 10.7 4.7 1 88.2 96.8
1974 11 9.8* 4.1 1 126.1 58.3
1974 12 10.6 5.7 0 28.3 52.0
1975 1 10.1 3.9 3 51.9 38.0
1975 2 8.3 1.2 10 25.2 53.7
1975 3 7.8 2.3 7 92.4 70.8
1975 4 12.6 4.6 5 79.7 128.6
1975 5 14.4 5.9 0 48.5 180.6
1975 6 20.8 8.8 0 18.0 282.3
1975 7 23.4 12.6 0 27.4 222.0
1975 8 25.3 13.5 0 26.2 234.3
1975 9 19.4 9.4 0 69.8 162.5
1975 10 14.2 6.3 0 6.4 126.6
1975 11 9.1 2.4 9 37.6 70.6
1975 12 7.4 1.7 10 28.1 30.5
1976 1 8.3 3.1 9 29.2 52.9
1976 2 7.2 1.5 9 14.4 53.5
1976 3 9.0 0.9 12 15.7 116.0
1976 4 12.9 3.9 4 21.4 175.0
1976 5 17.9 7.6 0 31.1 197.8
1976 6 24.5 11.4 0 8.3 277.8
1976 7 25.7 12.4 0 36.2 282.2
1976 8 24.2 10.7 0 33.2 238.2
1976 9 18.1 9.7 0 72.7 117.1
1976 10 14.4 8.2 0 85.2 57.3
1976 11 9.3 3.4 2 76.3 71.9
1976 12 4.5 -0.4 13 74.6 61.2
1977 1 5.3 0.6 12 45.7 43.5
1977 2 9.0 2.6 3 64.7 65.1
1977 3 11.0 3.6 5 33.7 98.8
1977 4 12.2 3.3 8 29.2 173.5
1977 5 15.7 5.5 0 39.9 236.8
1977 6 16.6 7.3 0 53.9 138.5
1977 7 21.3 10.2 0 4.7 208.7
1977 8 20.0 10.1 0 128.0 149.9
1977 9 18.1 9.3 0 13.7 126.5
1977 10 16.2 8.0 0 21.2 120.0
1977 11 9.6 3.7 4 48.3 86.9
1977 12 9.0 3.9 3 51.6 48.8
1978 1 5.9 -0.7 15 61.5 39.6
1978 2 5.4 0.1 14 39.0 54.4
1978 3 11.1 3.2 2 58.9 116.1
1978 4 10.3 2.6 4 44.7 103.2
1978 5 16.0 6.1 0 77.9 187.4
1978 6 18.9 9.3 0 45.9 154.8
1978 7 19.4 10.4 0 36.9 112.7
1978 8 20.2 11.1 0 32.8 137.1
1978 9 19.3 10.8 0 40.2 163.1
1978 10 16.3 8.6 0 5.2 98.7
1978 11 11.7 5.0 5 13.7 84.9
1978 12 6.7 1.6 10 99.3 37.2
1979 1 2.5 -3.0 23 42.8 56.4
1979 2 3.5 -1.3 19 46.3 44.0
1979 3 8.4 1.8 3 84.2 94.1
1979 4 12.1 4.2 1 33.2 113.8
1979 5 15.9 6.6 1 94.6 201.1
1979 6 18.9 9.8 0 13.3 177.8
1979 7 21.8 11.8 0 11.9 178.2
1979 8 20.4 11.0 0 74.7 170.7
1979 9 19.3 9.6 0 18.8 181.0
1979 10 15.5 7.2 0 61.4 120.0
1979 11 10.0 3.2 3 43.1 68.1
1979 12 8.8 3.3 4 104.0 62.4
1980 1 5.6 -0.2 12 33.7 65.0
1980 2 9.1 2.6 6 42.9 49.1
1980 3 8.5 1.8 7 57.5 80.5
1980 4 13.3 4.0 2 17.9 160.8
1980 5 16.4 5.7 2 7.6 229.6
1980 6 19.3 10.2 0 77.2 195.8
1980 7 19.3 10.8 0 55.9 161.8
1980 8 21.3 12.1 0 56.4 155.3
1980 9 19.5 11.1 0 13.4 155.6
1980 10 13.3 5.4 3 58.3 136.5
1980 11 8.9 3.7 4 41.2 55.7
1980 12 8.2 2.2 8 29.6 64.7
1981 1 7.4 1.7 12 35.8 50.4
1981 2 6.1 -0.2 17 15.8 62.6
1981 3 11.0 5.6 0 97.2 60.1
1981 4 11.7 3.8 3 56.0 143.3
1981 5 15.8 7.4 1 58.2 152.6
1981 6 18.1 9.7 0 14.2 165.0
1981 7 20.8 11.7 0 73.5 161.6
1981 8 21.7 11.9 0 27.3 180.0
1981 9 19.9 10.6 0 62.1 170.8
1981 10 12.4 5.5 2 72.0 140.3
1981 11 10.9 4.5 2 27.2 65.2
1981 12 3.0 -2.7 19 31.2 39.6
1982 1 5.6 -1.1 14 35.2 51.7
1982 2 7.9 1.8 6 20.3 47.3
1982 3 10.5 2.3 4 42.8 169.9
1982 4 13.4 3.9 4 10.0 160.6
1982 5 17.3 6.4 1 51.1 252.6
1982 6 20.2 11.9 0 107.4 163.6
1982 7 21.8 12.2 0 53.1 184.3
1982 8 21.3 12.0 0 72.3 187.8
1982 9 19.9 10.3 0 53.8 162.3
1982 10 13.6 7.5 0 125.8 82.9
1982 11 10.6 5.6 4 65.8 63.3
1982 12 7.2 1.1 14 48.9 56.6
1983 1 9.5 3.9 2 36.6 62.0
1983 2 4.5 -1.0 17 42.7 95.2
1983 3 10.2 3.2 1 35.4 87.8
1983 4 11.6 3.0 3 86.2 147.9
1983 5 14.8* 6.7 0 101.8 147.0
1983 6 19.4* 10.2 0 33.3 193.1
1983 7 25.8 13.5 0 48.6 242.4
1983 8 23.4 12.6 0 10.5 220.8
1983 9 18.2 10.9 0 70.3 127.1
1983 10 14.7 7.1 3 33.5 134.7
1983 11 10.4 4.8 6 45.4 38.8
1983 12 8.3 2.8 8 35.8 60.9
1984 1 6.9 0.6 9 61.9 96.5
1984 2 6.2 0.6 8 42.0 67.0
1984 3 8.0 1.9 4 31.0 44.9
1984 4 13.4 2.0 5 13.6 231.0
1984 5 14.0 5.1 0 76.1 130.3
1984 6 19.5 10.0 0 48.9 210.0
1984 7 22.3 11.2 0 15.0 213.6
1984 8 23.6 12.4 0 60.9 199.1
1984 9 17.5 10.5 0 113.3 103.5
1984 10 15.6 7.6 0 48.9 113.5
1984 11 11.2 5.9 0 87.6 49.0
1984 12 8.2 2.6 9 35.1 67.5
1985 1 3.4 -2.2 23 37.3 40.7
1985 2 4.9 -1.9 13 14.6 79.0
1985 3 8.7* 1.1 10 45.8 97.8
1985 4 12.9* 4.9 2 31.2 139.3
1985 5 15.4* 7.1 0 49.0 132.7
1985 6 17.4* 8.7 0 107.0 142.9
1985 7 21.8 12.4 0 38.5 194.4
1985 8 20.1 11.2 0 50.9 158.4
1985 9 20.1 10.6 0 18.6 123.1
1985 10 15.6 7.3 1 12.4 111.9
1985 11 7.1 1.1 11 35.3 93.3
1985 12 9.2 4.8 4 73.1 29.0
1986 1 6.3 0.8 9 50.2 75.0
1986 2 0.8 -4.0 24 10.4 60.2
1986 3 9.3 1.3 8 43.2 129.0*
1986 4 9.8 2.7* 4* 63.6 116.3
1986 5 16.3 7.4 0 74.7 189.8
1986 6 20.7 9.6 0 13.2 200.8
1986 7 21.7 12.0 0 43.3 172.3
1986 8 19.1 10.4 0 70.9 137.8
1986 9 17.1 6.5 0 29.3 166.9
1986 10 15.6 6.4 1 69.7 114.6
1986 11 11.0 4.4 1 54.5 75.9
1986 12 9.0 2.7 3 54.2 62.8
1987 1 2.8 -2.1 22 9.5 44.5
1987 2 7.0* -0.1 16 27.8 58.1
1987 3 7.7* 0.0 17 44.9 97.4
1987 4 15.2 5.6 0 42.9 151.5
1987 5 14.9 5.3 0 46.9 166.8
1987 6 17.5 9.2 0 93.5 106.6
1987 7 20.6 11.9 0 70.2 148.1
1987 8 20.5 11.7 0 71.9 130.8
1987 9 18.8 10.1 0 30.5 151.5
1987 10 14.1 6.1 2 116.4 120.7
1987 11 9.0 4.0 2 39.9 42.0
1987 12 8.2 3.3 6 23.5 29.3
1988 1 8.0 2.7 6 100.3 58.1
1988 2 7.9 2.0 5 20.9 123.0
1988 3 9.7 3.1 4 59.3 86.6
1988 4 12.5* 4.1 5 37.2 118.8
1988 5 17.0 7.5 0 38.7 162.5
1988 6 18.3 9.9 0 48.1 141.6
1988 7 19.4 11.7 0 94.6 153.4
1988 8 21.4 11.4 0 46.8 191.6
1988 9 18.2* 10.0 0 45.8 137.9
1988 10 14.6* 7.8 3 42.7 103.5
1988 11 9.0* 1.2 13 31.0 79.5
1988 12 9.6 4.9 0 23.6 45.6
1989 1 8.9 3.1 4 25.8 73.7
1989 2 9.6 2.6 5 47.5 103.5
1989 3 12.3 4.1 2 40.0 98.1
1989 4 10.6 3.1 2 75.8 123.7
1989 5 19.7 7.2 0 6.1 269.1
1989 6 21.2 9.5 0 40.5 215.8
1989 7 24.8 13.2 0 43.0 225.5
1989 8 24.1 12.1 0 28.8 238.2
1989 9 20.5 11.8 0 17.7 116.6
1989 10 16.5 9.1 0 32.2 94.9
1989 11 9.9 2.5 6 35.3 98.3
1989 12 8.3 3.1 5 125.4 22.9
1990 1 9.8 4.0 0 43.8 64.7
1990 2 11.4 4.7 1 71.1 102.0
1990 3 12.9* 4.7 3 23.2 153.2
1990 4 13.5 3.1 7 28.2 206.3
1990 5 19.1 6.7 0 6.2 225.7
1990 6 19.2 9.8 0 30.1 112.5
1990 7 23.7 11.5 0 16.9 224.8
1990 8 25.7 13.6 0 21.1 230.8
1990 9 18.6 8.9 0 37.3 136.8
1990 10 16.2 9.5 0 43.7 126.3
1990 11 9.8 4.5 1 40.5 40.6
1990 12 6.9 2.3 5 45.8 43.1
1991 1 6.2 1.2 8 29.9 75.6
1991 2 4.6 -1.8 20 23.0 45.3
1991 3 12.0 4.7 2 37.9 100.3
1991 4 12.4 4.0 3 42.9 147.1
1991 5 14.7 6.6 1 13.9 114.5
1991 6 16.7 8.8 0 97.6 113.5
1991 7 22.9 13.1 0 32.1 192.7
1991 8 23.7 12.8 0 41.2 209.8
1991 9 20.5 9.8* 0* 46.5 176.1
1991 10 14.1 6.9 1 18.5 88.9
1991 11 9.8 4.2 3 54.9 51.0
1991 12 7.3 1.2 12 11.9 43.8
1992 1 6.4 1.4 10 67.8 49.5
1992 2 9.2 2.0 8 14.0 56.1
1992 3 11.1 4.6 0 58.0 74.0
1992 4 13.2 4.9 1 40.7 115.7
1992 5 19.8 8.1 0 34.3 234.2
1992 6 21.7 10.7 0 35.8 185.2
1992 7 21.8 13.1 0 54.4 138.8
1992 8 21.2 12.2 0 72.4 163.0
1992 9 18.4 10.0 0 82.0 127.7
1992 10 11.5 5.1 0 91.6 97.9
1992 11 10.8 4.2 1 78.2 62.5
1992 12 6.4 0.5 15 31.6 42.5
1993 1 9.6 2.9 5 51.3 39.8
1993 2 6.6 2.3 3 11.6 37.4
1993 3 10.7 3.1 7 19.9 125.0
1993 4 13.4 6.3 0 78.4 108.4
1993 5 17.2 7.6 0 47.9 185.7
1993 6 20.4 10.5 0 86.0 186.6
1993 7 20.5 11.5 0 54.4 169.1
1993 8 20.5 10.6 0 37.5 196.3
1993 9 16.7 9.6 0 67.4 95.1
1993 10 12.1 6.2 5 88.9 107.6
1993 11 7.9 2.1 11 53.5 59.3
1993 12 8.5 2.6 5 78.3 43.5
1994 1 8.5 2.3 7 70.5 66.6
1994 2 6.7 0.0 13 34.4 82.8
1994 3 11.7 4.2 0 36.1 134.1
1994 4 12.4 4.3 3 67.3 164.5
1994 5 15.1 7.1 0 44.1 135.9
1994 6 20.3 10.3 0 20.0 219.6
1994 7 25.8 13.1 0 23.0 222.1
1994 8 22.1 13.0 0 36.4 176.9
1994 9 16.6 10.1 0 72.1 103.2
1994 10 13.9 7.9 0 74.9 108.2
1994 11 12.6 7.0 1 27.3 36.6
1994 12 9.8* 2.5 10 41.7 66.7
1995 1 7.9* 1.7 6 86.5 56.9
1995 2 9.6 3.3 2 63.1 84.4
1995 3 9.9 1.6 12 50.8 185.8
1995 4 13.9 4.5 4 10.2 161.7
1995 5 17.9 6.2 1 24.4 202.5
1995 6 18.7 9.3 0 17.3 159.7
1995 7 25.8 13.4 0 27.1 234.9
1995 8 25.7 13.1 0 5.3 243.7
1995 9 18.0 10.4 0 105.4 114.8
1995 10 17.6 9.5 1 12.7 149.4
1995 11 10.9 5.0 3 29.4 67.3
1995 12 4.3 -0.4* 15* 63.9 29.5
1996 1 5.8 1.7 8 33.2 21.9
1996 2 5.4 -1.0 18 45.8 82.6
1996 3 7.2 1.0 9 19.5 59.7
1996 4 13.7 3.8 6 4.5 148.9
1996 5 13.9 4.3 6 19.8 155.8
1996 6 21.5 9.4 0 12.4 225.6
1996 7 23.2 11.7 0 40.5 207.4
1996 8 22.6 12.6 0 63.9 176.3
1996 9 18.4 10.1 0 5.6 130.8
1996 10 15.9 8.2 0 31.2 143.0
1996 11 9.3 2.7 12 70.9 92.1
1996 12 5.1 0.3 15 30.2 52.5
1997 1 4.7 -1.2 22 11.6 51.8
1997 2 10.5 3.5 3 38.7 60.0
1997 3 13.0 4.9 0 7.0 144.8
1997 4 13.9 3.9 4 12.5 159.3
1997 5 17.6 6.5 1 36.8 222.4
1997 6 18.9 11.0 0 151.0 135.7
1997 7 22.3 11.6 0 25.9 199.3
1997 8 26.3 14.1 0 60.5 188.2
1997 9 19.9 10.3 0 15.0 162.4
1997 10 14.7 5.8 7 45.1 146.7
1997 11 11.7 5.1 4 40.4 48.3
1997 12 8.5 3.0 7 62.4 39.7
1998 1 8.1 2.5 6 48.1 46.8
1998 2 11.2 3.2 4 4.8 119.9
1998 3 11.5 4.6 3 45.2 73.8
1998 4 11.9 5.5 1 120.4 111.2
1998 5 18.2 7.1 0 6.4 183.6
1998 6 18.9 10.8 0 101.9 132.5
1998 7 20.8 11.7 0 25.7 144.0
1998 8 22.6 11.1 0 16.0 201.5
1998 9 19.4 11.9 0 104.0 121.5
1998 10 14.0 8.1 1 77.3 102.2
1998 11 8.4 2.4 6 55.1 66.4
1998 12 8.7 2.4 10 59.8 37.5
1999 1 9.1 2.4 6 50.2 68.6
1999 2 8.2 1.8 9 36.1 96.6
1999 3 11.7 4.0 2 40.9 103.4
1999 4 14.3 5.2 3 33.0 153.8
1999 5 18.3 8.3 0 49.8 161.4
1999 6 19.2 9.7 0 89.0 197.9
1999 7 24.5 12.5 0 24.5 233.2
1999 8 21.6 12.4 0 92.5 138.7
1999 9 21.3 11.9 0 76.4 148.5
1999 10 14.9 7.3 0 43.7 137.0
1999 11 10.6 5.1 0 25.3 63.3
1999 12 7.8 1.8 8 63.1 76.1
2000 1 8.1 1.8 11 20.5 78.6
2000 2 9.8 2.8 5 50.7 106.4
2000 3 11.2 4.0 2 14.6 109.2
2000 4 12.4 4.5 4 85.9 138.0
2000 5 16.8 8.5 0 83.8 161.2
2000 6 20.5 11.3 0 17.5 162.0
2000 7 20.1 11.8 0 60.7 126.9
2000 8 23.1 12.6 0 21.1 207.7
2000 9 20.0 12.6 0 68.1 126.5
2000 10 14.0 8.0 0 108.0 98.7
2000 11 10.4 3.8 2 108.8 69.6
2000 12 8.1 3.5 9 59.6 50.0
2001 1 6.1 0.4 14 47.2 83.8
2001 2 8.2 0.9 14 72.4 77.2
2001 3 9.0 2.0 8 77.4 87.7
2001 4 12.1 3.9 1 62.6 132.0
2001 5 18.5 7.2 0 17.5 220.7
2001 6 19.9 9.6 0 22.8 194.0
2001 7 23.1 13.2 0 55.1 178.7
2001 8 22.9 13.3 0 65.8 180.5
2001 9 17.3 10.1 0 68.9 114.9
2001 10 17.3 10.9 0 128.9 107.7
2001 11 10.6 4.0 4 36.4 73.7
2001 12 6.2 0.4 18 19.3 72.0
2002 1 8.9 2.6 8 33.0 48.8
2002 2 10.7 3.7 4 50.4 82.5
2002 3 12.0 3.0 7 30.6 122.9
2002 4 14.7 4.2 2 33.4 196.2
2002 5 16.6 7.9 0 53.5 180.2
2002 6 20.1 10.3 0 28.5 182.1
2002 7 22.0 12.3 0 94.6 172.2
2002 8 22.9 13.2 0 42.0 143.8
2002 9 19.6 10.0 0 23.5 147.6
2002 10 14.3 6.7 0 67.7 94.4
2002 11 11.4 5.7 2 85.9 47.3
2002 12 8.2 3.9* 4* 85.1 20.4
2003 1 7.0 1.6 12 78.6 53.0
2003 2 7.8 0.8 12 12.9 101.5
2003 3 12.9 2.4 8 13.7 164.0
2003 4 15.1 4.5 4 24.2 178.3
2003 5 17.5 7.5 0 39.9 190.0
2003 6 22.1 11.5 0 60.7 210.0
2003 7 23.7 13.3 0 66.8 184.6
2003 8 25.3 13.3 0 2.0 214.1
2003 9 21.3 8.9 0 15.7 196.3
2003 10 14.0 4.8 1 30.0 141.8
2003 11 11.7 5.9 1 80.8 72.9
2003 12 8.1 2.3 7 46.0 57.8
2004 1 8.1 2.7 7 69.6 49.2
2004 2 8.1 3.3 11 34.3 72.6
2004 3 10.5 3.2 3 24.7 96.2
2004 4 14.2 5.5 0 41.4 138.9
2004 5 16.9 7.9 0 44.5 162.7
2004 6 21.2 11.2 0 34.0 190.9
2004 7 22.0 11.6 0 59.3 173.8
2004 8 24.0 14.1 0 70.7 184.8
2004 9 20.6 11.1 0 18.7 169.8
2004 10 15.0 7.8 0 67.2 99.0
2004 11 10.5 5.5 3 45.4 56.6
2004 12 8.4 2.5 9 32.2 51.4
2005 1 9.2 3.1 5 28.3 66.3
2005 2 7.1 1.9 9 22.3 67.0
2005 3 10.7 3.8 7 19.8 66.0
2005 4 14.2 4.3 4 27.7 130.6
2005 5 16.6 7.0 0 47.4 197.6
2005 6 21.8 10.9 0 47.1 175.8
2005 7 22.0 12.8 0 43.7 157.5
2005 8 22.6 11.5 0 53.3 182.5
2005 9 21.1 11.3 0 166.2 148.1
2005 10 17.4 10.5 0 61.2 107.1
2005 11 10.1 3.0 9 47.2 101.0
2005 12 7.8 1.8 10 18.0 75.1
2006 1 7.0 1.5 12 19.8 48.8
2006 2 7.0 1.5 5 25.2 71.1
2006 3 9.0 1.7 12 35.9 105.2
2006 4 13.5 5.1 3 30.1 144.5
2006 5 17.4 8.7 0 62.8 155.7
2006 6 22.5 11.2 0 18.9 220.2
2006 7 28.3 14.1 0 45.1 253.5
2006 8 21.5 12.2 0 74.9 152.5
2006 9 22.7 13.4 0 50.0 164.7
2006 10 17.5 10.5 0 43.2 111.4
2006 11 12.5 5.1 2 64.8 109.0
2006 12 9.7 3.3 6 50.5 41.0
2007 1 10.4 3.8 5 68.5 66.2
2007 2 9.7 2.3 8 50.9 70.4
2007 3 12.1 3.2* 1* 25.7 161.1
2007 4 17.1 6.0* 1* 1.0 183.1
2007 5 16.9 8.3* 0* 124.3 121.7
2007 6 20.4 11.1 0 59.0 148.9
2007 7 21.6 11.0 0 62.1 189.7
2007 8 21.6 10.8 0 51.1 180.4
2007 9 19.5 10.0 0 25.2 158.1
2007 10 15.2 7.2 0 56.4 97.3
2007 11 11.1 3.7 5 36.3 77.2
2007 12 8.5 1.9 12 38.2 51.9
2008 1 10.3 3.8 0 58.0 63.2
2008 2 9.9 0.6 11 12.8 105.2
2008 3 10.1 3.0 5 68.9 117.0
2008 4 13.1 3.8 3 50.8 158.2
2008 5 19.0 7.9 0 62.9 173.9
2008 6 19.7 10.4 0 34.6 181.8
2008 7 22.8 12.4 0 52.1 188.1
2008 8 22.3 13.3 0 64.7 122.7
2008 9 18.6 9.6 0 59.5 103.3
2008 10 14.4 6.1 1 56.2 130.3
2008 11 10.3 4.7 5 68.8 55.5
2008 12 6.6 1.4 11 21.3 68.0
2009 1 5.8 0.2 13 40.9 46.2
2009 2 7.1 1.8 13 47.9 42.1
2009 3 11.9 2.8 6 32.2 149.7
2009 4 15.6 5.4 0 12.6 166.1
2009 5 18.3 7.7 0 28.4 204.0
2009 6 20.9 10.2 0 40.8* 198.8*
2009 7 22.5 12.1 0 71.0 196.9*
2009 8 23.6 13.1 0 58.6 200.0*
2009 9 20.1 10.5 0 10.0 152.5*
2009 10 15.7 8.3 0 32.2 87.8*
2009 11 12.0 6.5 0 89.8 78.7*
2009 12 6.2 0.6 12 63.2 68.5*
2010 1 3.9 -0.4 15 46.6 55.2*
2010 2 6.1 0.4 12 70.6 54.9*
2010 3 10.9 2.8 9 26.2 118.4*
2010 4 14.9 3.7 3 12.5 212.1*
2010 5 16.5 5.9 2 28.6 209.4*
2010 6 21.6 10.0 0 25.4 229.9*
2010 7 24.6 13.8 0 10.8 ---
2010 8 21.0 12.2 0 133.2 ---
2010 9 19.0 10.5 0 46.4 ---
2010 10 14.7 7.7 0 39.0 ---
2010 11 8.4 3.0 9 22.4 ---
2010 12 2.8 -2.7 23 19.8 ---
2011 1 6.8 2.2 7 52.4 ---
2011 2 9.6 4.0 2 28.2 ---
2011 3 11.6 2.7 5 1.8 ---
2011 4 18.6 6.5 0 2.0 ---
2011 5 18.7 7.8 1 12.8 ---
2011 6 20.3 9.9 0 53.0 ---
2011 7 21.2 10.9 0 38.4* ---
2011 8 21.6 11.9 0 40.2 ---
2011 9 21.2 11.3 0 31.6 ---
2011 10 17.9 9.3 0 15.8 ---
2011 11 13.3 6.6 2 28.0 ---
2011 12 9.1 3.2 3 43.0 ---
2012 1 9.1 2.8 7 39.0 ---
2012 2 7.0 0.1 12 17.4 ---
2012 3 13.3 2.6 5 23.4 ---
2012 4 12.2 3.9 2 95.6 ---
2012 5 16.9 7.9 0 42.6 ---
2012 6 18.5 10.4 0 91.4 ---
2012 7 21.2 12.0 0 101.4 ---
2012 8 23.5 12.9 0 39.2 ---
2012 9 19.3 8.9 0 30.0 ---
2012 10 13.5 6.9 0 78.6 ---
2012 11 10.0 4.0 2 71.0 ---
2012 12 8.1 2.1 10 97.7* ---
2013 1 5.8 0.5 16 39.8 ---
2013 2 6.0 0.6 9 19.6 ---
2013 3 6.2 0.1 16 38.6 ---
2013 4 13.2 3.4 11 26.4 ---
2013 5 15.9 6.1 1 52.0 ---
2013 6 19.2 9.7 0 14.2 ---
2013 7 25.1 12.8 0 32.8 ---
2013 8 23.5 13.0 0 48.2 ---
2013 9 19.0 10.0 0 34.8 ---
2013 10 16.2 9.8 0 78.2 ---
2013 11 9.6 3.7 2 40.2 ---
2013 12 9.7 3.1 1 36.0 ---
2014 1 9.2 3.1 4 103.6 ---
2014 2 9.8 3.8 0 61.2 ---
2014 3 13.4 3.4 4 17.4 ---
2014 4 15.9 6.3 2 13.8 ---
2014 5 17.7 8.7 0 84.6 ---
2014 6 20.8 10.7 0 44.4 ---
2014 7 24.4 13.5 0 49.2 ---
2014 8 21.0 11.8 0 126.8 ---
2014 9 20.5 11.0 0 23.0 ---
2014 10 17.0 9.9 0 67.2 ---
2014 11 11.9 5.8 3 58.4 ---
2014 12 8.5 2.8 8 40.2 --- Provisional
2015 1 8.0 1.3 12 48.4* --- Provisional
2015 2 7.4 1.2 10 30.8 --- Provisional
2015 3 11.1 3.1 4 19.4 --- Provisional
"""
# create a list for all the tuples of interest
L = []
# process each line in the input string
for line in text.split( "\n" ):
# remove extra blank characters
line = line.strip()
# skip empty lines
if len( line ) == 0:
continue
# skip lines that do not start with '1' or '2'
if not line[0] in ['2', '1']:
continue
# remove '*' and 'Provisional' from lines
line = line.replace( "*", "" ).replace( "Provisional", "" ).strip()
# split around white space characters
fields = line.split( )
# if the line does not contain 7 fields, it's not valid for us. Skip it!
if len( fields ) != 7:
continue
# if the rain data is missing, skip as well
if fields[5] == "---":
continue
# get the 3 fields of interest
year = fields[0]
month = fields[1]
rain = float( fields[5] )
# create a tuple and add it to the list
tuple = ( rain, year, month )
L.append( tuple )
# sort the list, lowest rain recorded first.
L.sort()
# reverse the list, highest rain recorded first
L.reverse()
# get the first 10 tuples, corresponding to the 10 rainiest days
L10 = L[0:10]
# display the year, month, and rain amount for the 10 rainiest records
for rain, year, month in L10:
print( year, month, rain )
Emails.txt
The list below simulates the different list of email addresses for students taking computer-science related courses a given semester. We want to combine the different lists in one list, remove the duplicates, and generate a separate list with smith.edu email addresses, and one list with non smith.edu ones.
Ammie@hampshire.edu
Bessie@smith.edu
Carylon@smith.edu
Cheryll@smith.edu
Cordelia@smith.edu
Illa@smith.edu
Lisbeth@smith.edu
Mackenzie@smith.edu
Maryellen@smith.edu
Matha@smith.edu
Patrica@hampshire.edu
Sanjuana@smith.edu
Sharie@smith.edu
Sonya@smith.edu
Yuko@smith.edu
Cheryll@smith.edu
Codi@smith.edu
Cordelia@smith.edu
Elenore@smith.edu
Emelia@smith.edu
Josie@smith.edu
Lina@smith.edu
Lisbeth@smith.edu
Mackenzie@smith.edu
Margaretta@smith.edu
Rosalina@smith.edu
Sade@smith.edu
Sanjuana@smith.edu
Shelli@smith.edu
Sonya@smith.edu
Aja@hampshire.edu
Alesia@hampshire.edu
Bessie@smith.edu
Carylon@smith.edu
Chun@smith.edu
Codi@smith.edu
Constance@smith.edu
Felisa@smith.edu
Illa@smith.edu
Karena@hampshire.edu
Kortney@hampshire.edu
Lina@smith.edu
Mallie@smith.edu
Patrica@hampshire.edu
Zofia@smith.edu
Anna@hampshire.edu
Bessie@smith.edu
Candyce@smith.edu
Clorinda@smith.edu
Elenore@smith.edu
Karine@hampshire.edu
Kaylee@hampshire.edu
Kortney@hampshire.edu
Lisbeth@smith.edu
Marline@smith.edu
Matha@smith.edu
Porsha@hampshire.edu
Renata@smith.edu
Sanjuana@smith.edu
Sonya@smith.edu
Ammie@hampshire.edu
Anna@hampshire.edu
Birdie@smith.edu
Codi@smith.edu
Constance@smith.edu
Edelmira@smith.edu
Kaylee@hampshire.edu
Kristel@hampshire.edu
Margaretta@smith.edu
Moira@smith.edu
Patrica@hampshire.edu
Phuong@hampshire.edu
Sade@smith.edu
Tamela@smith.edu
Yuko@smith.edu
processEmails.py
file =open( "emailAddresses.txt", "r" )
emails = file.read()
file.close()
# parse the file. Add each valid email in the list
L = []
for email in emails.split( "\n" ):
email = email.strip().lower()
if len( email ) == 0:
continue
L.append( email )
# remove duplicates by putting the list in a set, and transforming the set back
# into a list
L = list( set( L ) )
# print the list of Smith emails
print( "\nSMITH EMAILS" )
for email in L:
if email.find( "@smith" ) != -1:
print( email )
# print the list of 5-College (non-Smith) emails
print( "\n5-COLLEGE EMAILS" )
for email in L:
if email.find( "@smith" ) == -1:
print( email )
inheritance1.py
This program simply displays a car with a body and 2 wheels. The Car class will become the super class for new derived classes.
from graphics import * WIDTH = 600 HEIGHT = 400 class Wheel: """a Wheel is 2 concentric circles, the larger one black, the smaller one grey.""" def __init__(self, centr, rad1, rad2 ): # make circ1 the smaller of the 2 circles self.circ1 = Circle( centr, min( rad1, rad2 ) ) self.circ2 = Circle( centr, max( rad1, rad2 ) ) self.circ1.setFill( "grey" ) self.circ2.setFill( "black" ) def draw( self, win ): self.circ2.draw( win ) self.circ1.draw( win ) def move( self, dx, dy ): self.circ2.move( dx, dy ) self.circ1.move( dx, dy ) class Car: """A default simple car class. Sets the color to "Yellow" """ def __init__( self, rp ): x = rp.getX() y = rp.getY() length = 180 height = length // 3 firstQuarter = length//4 thirdQuarter = length * 3 // 4 p2 = Point( x+length, y+height ) self.body = Rectangle( rp, p2 ) self.body.setFill( "yellow" ) self.w1 = Wheel( Point( x+firstQuarter, y+height ), 20,10 ) self.w2 = Wheel( Point( x+thirdQuarter, y+height ), 20,10 ) def draw( self, win ): self.body.draw( win ) self.w1.draw( win ) self.w2.draw( win ) def move( self, dx, dy ): self.body.move( dx, dy ) self.w1.move( dx, dy ) self.w2.move( dx, dy ) def main(): # open the window win = GraphWin( "CSC111 Inheritance Demo", WIDTH, HEIGHT ) car = Car( Point( 100,250 ) ) car.draw( win ) win.getMouse() win.close() main()