Asn0: Places
places.py
"Classes" version, with disk=file reading.
"""
Created on Mon Feb 15 13:05:08 2021
@author: rmontant
"""
class Place:
def __init__(self, name, lat, long, pop):
self.name = name
self.coords = (lat, long)
self.size = pop
def relative(self, other):
if self.coords[0] < other.coords[0]:
return 'south of'
else:
return 'lost'
def ratio(self, other):
return other.size / self.size
handle = open('//buad.bloomu.edu/data/UsersMNO/rmontant/Downloads/earthquakes-fixed.csv', 'r')
places = []
for line in handle.readlines():
if line[0] == '#':
continue
ts = line[3:26]
lat = float( line[26:40] )
long = float( line[40:55] )
locn = line[78:]
l = Place(locn, lat, long, float(line[66:74]))
places.append(l)
handle.close()
print(len(places), 'total earthquakes')
big = 0
for place in places:
if place.size > 5:
print('{:26s} {:6.1f}Lat, {:6.1f}Long, {:3f}' \
.format(place.name, place.coords[0],place.coords[1], place.size))
big += 1
print('{:d} big earthquakes'.format(big))