-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathearthquake_.py
207 lines (125 loc) · 4.83 KB
/
earthquake_.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# -*- coding: utf-8 -*-
"""
A program to analyze earthquake data in the past week.
@author: Sackitey Joseph
"""
import earthquake
def number_of_earthquakes(earthquake, magnitude=0):
"""
Determines the number of earthquakes in the past week and
calculate the number of earthquakes with magnitude above or eqaul to a specified magnitude
Parameters
----------
earthquake : list
A list of earthqaukes in the past week
magnitude : int, optional
It is the magnitude to determine the numbert of earthquakes with magnitude above it.
The default is 0.
Returns
-------
number_of_earthquake : int
Value of the total number of earthquakes.
above_magnitude : int
Value of total number of earthquakes with magnitrude equal to or above specified magnitude.
"""
number_of_earthquake = 0
above_magnitude = 0
number_of_earthquake = len(earthquake)
if magnitude != 0:
magnitudes_list = []
for section in earthquake:
magnitudes_list.append(section[6])
for value in magnitudes_list:
if value >= magnitude:
above_magnitude += 1
return number_of_earthquake, above_magnitude
def location_with_most_earthquake(earthquake):
"""
Determines the location with most occurence of earthquakes
Parameters
----------
earthquake : list
The list of all the data collected in the past week
Returns
-------
common_name : string
name of location with most occurence of earthquake
"""
locations=[]
common_name=[]
for section in earthquake:
locations.append(section[7])
common_name.append(max(locations, key=locations.count))
for name in common_name:
print(name)
return name
def highest_earthquake(earthquake):
"""
Determines the name highest magnitude of earthquake and where it was recorded
Parameters
----------
earthquake : list
The list of all the data collected in the past week.
Returns
-------
name_of_place : string
name of place with highest magnitude of earthquake
highest_earthquake : int
magnitude of the highest earthquake recorded
"""
magnitudes_list=[]
name_of_place=[]
for section in earthquake:
magnitudes_list.append(section[6])
highest_earthquake = max(magnitudes_list)
for section in earthquake:
if section[6]== highest_earthquake:
name_of_place.append(section[8])
for name in name_of_place:
print(name)
return name, highest_earthquake
def average_earthquake(earthquake,default_depth=100):
"""
Calculates average magnitude of all earthquakes with depth grester than 100
Parameters
----------
earthquake : list
The list of all the data collected in the past week.
Returns
-------
average_magnitude : int
average magnitude of earthquakes with depth above 100
"""
depth_list=[]
magnitudes_list=[]
average_list=[]
for section in earthquake:
magnitudes_list.append(section[6])
depth_list.append(section[5])
for depth in depth_list:
if depth > default_depth:
average_list.append(magnitudes_list[depth_list.index(depth)])
average_magnitude= sum(average_list)/len(average_list)
return average_magnitude
print("Earthquake Data for the Past Week")
print()
def main():
"""
Prints out the returns of the various functions.
Returns
-------
None.
"""
magnitude= 5 # Magnitude to be compared can be varied here
depth= 100 #depth to be used can be varied here
number_earthquake, magnitude_above_five = number_of_earthquakes(earthquake.data,magnitude)
location_name= location_with_most_earthquake(earthquake.data)
name_of_place,highest_ =highest_earthquake(earthquake.data)
average_mag=average_earthquake(earthquake.data,depth)
print(f"Number of Earthquakes: {number_earthquake}\n\nEarthquake with magnitude of {magnitude} or above: {magnitude_above_five}\n")
print(f"Location with most earthquakes: {location_name}\n")
print(f"Magnitude of highest recorded earthquake: {highest_}\n")
print(f"Highest earthquake recorded at: {name_of_place}\n")
print(f"Average magnitude of earthquake with depth greater than {depth}: {average_mag:.2f}\n")
# calling the main function to print all outputs
main()