from math import * class Coordinate: def __init__(self, deg_latitude, deg_longitude): self.latitude = radians(deg_latitude) self.longitude = radians(deg_longitude) def __str__(self): return str(self.latitude) + ", " + str(self.latitude) class Measurement: def __init__(self, date, time, magnitude, coordinate): self.date = date self.time = time self.magnitude = magnitude self.coordinate = coordinate def __str__(self): return "Erdbeben der Stärke " + str(self.magnitude) + ", gemessen am " \ + str(self.date) + " um " + str(self.time) + " an Position " + str(self.coordinate) def read_measurements(filename): # Datei Zeile für Zeile einlesen with open(filename) as file: lines = file.read().splitlines() measurements = {} # Alle Zeilen nacheinander verarbeiten for i in range(1, len(lines)): tmp = lines[i].split(";") tmp_coord = Coordinate(float(tmp[4]), float(tmp[5])) tmp_date_time = tmp[1].split(" ") tmp_magnitude = float(tmp[9]) tmp_meas = Measurement(tmp_date_time[1], tmp_date_time[2], tmp_magnitude, tmp_coord) measurements[int(float(tmp[0]))] = tmp_meas return measurements earthquakes = read_measurements("earthquakes.csv") while True: user_input = input("Geben Sie eine Erdbeben-ID ein (Abbrechen mit exit): ") if user_input == "exit": print("Programm beendet.") break else: quake_id = int(user_input) if quake_id not in earthquakes: print("Erdbeben-ID nicht gefunden.") else: print(earthquakes[quake_id])