runtime
304 / 500
question 304 HTTP & API Clients · easy

Validate an earthquake feature

Before storing earthquakes from the USGS feed, an importer checks each GeoJSON feature, because a mirror once sent damaged data. Write feature_problems(feature): return a list of problems, in the order of the rules below, or [] for a good feature.

Functionfeature_problems(feature)
Rule 1id missing or empty → "missing id"
Rule 2properties.mag isn't an int or float → "mag is not a number" (True/False don't count as numbers)
Rule 3geometry.coordinates isn't a list of exactly 3 numbers → "bad coordinates"; otherwise longitude outside −180…180 → "longitude out of range", latitude outside −90…90 → "latitude out of range"
Missing partsa missing properties or geometry counts as empty, so its rules fail
Examples
callfeature_problems({'type': 'Feature', 'properties': {'mag': 5.5, 'place': '153 km S of Isangel, Vanuatu', 'time': 1735706358208, 'type': 'earthquake', 'title': 'M 5.5 - 153 km S of Isangel, Vanuatu'}, 'geometry': {'type': 'Point', 'coordinates': [169.3819, -20.9273, 22]}, 'id': 'us6000pgsd'})returns[]
callfeature_problems({'id': 'us6000pgsd', 'properties': {'mag': '5.5'}, 'geometry': {'coordinates': [169.3819, -20.9273]}})returns['mag is not a number', 'bad coordinates']
callfeature_problems({'id': '', 'properties': {'mag': 4.7}, 'geometry': {'coordinates': [151.6536, -3.8682, 10]}})returns['missing id']

Loading your progress…

Validate an earthquake feature — Python practice · Runtime