self.lat=math.radians(float(input()))
import math
class Distance:
def __init__(self,lat=0,long=0):
self.lat=lat
self.long=long
def rad(self):
self.lat=math.radians(float(input(f'Enter the latitude {self} point: ')))
self.long=math.radians(float(input(f'Enter the longitude {self} point: ')))
return self
def dist(A,B):
return 6371.01*math.acos(math.sin(A.lat)*math.sin(B.lat)+math.cos(A.lat)*math.cos(B.lat)*math.cos(A.long-B.long))
A=Distance().rad()
B=Distance().rad()
print(dist(A,B))
import math
class Distance:
def __init__(self, lat=0, long=0, name="test"):
self.lat = lat
self.long = long
self.name = name
def rad(self):
self.lat = math.radians(float(input(f"Enter the latitude {self.name} point: ")))
self.long = math.radians(
float(input(f"Enter the longitude {self.name} point: "))
)
return self
def dist(A, B):
return 6371.01 * math.acos(
math.sin(A.lat) * math.sin(B.lat)
+ math.cos(A.lat) * math.cos(B.lat) * math.cos(A.long - B.long)
)
A = Distance(name="A").rad()
B = Distance(name="B").rad()
print(dist(A, B))
import math
class Distance:
def __init__(self, lat, long):
self._lat = math.radians(lat)
self._long = math.radians(long)
@property
def lat(self):
return self._lat
@property
def long(self):
return self._long
def __repr__(self):
return f"latitude - {self._lat} longitude - {self._long}"
class DistanceCalculator:
K_CONST = 6371.01
def calculate(self, point_a: Distance, point_b: Distance):
return self.K_CONST * math.acos(
math.sin(point_a.lat) * math.sin(point_b.lat) +
math.cos(point_a.lat) * math.cos(point_b.lat) *
math.cos(point_a.long - point_b.long)
)
class GUI:
ACCEPTED_ACTIONS = {1: "Рассчёт дистанции", 2: "Выход"}
ACCEPTED_ACTIONS_STR = "\n".join([f"{k}: {v}" for k, v in ACCEPTED_ACTIONS.items()])
def main(self):
while True:
action = input(f'Выберите действие:\n{self.ACCEPTED_ACTIONS_STR}\n')
try:
int_act = int(action)
if int_act not in self.ACCEPTED_ACTIONS:
raise ValueError('Недопустимый пункт меню')
if int_act == 1:
a = self.get_distance("A")
b = self.get_distance("B")
calc = DistanceCalculator()
distance = calc.calculate(a, b)
print(f'Distance between {a} and {b} is {distance}')
elif int_act == 2:
print('Выход')
break
except (TypeError, ValueError) as E:
print(E)
def get_distance(self, point: str):
latitude = float(input(f'Enter the latitude point {point}: '))
longitude = float(input(f'Enter the longitude point {point}: '))
return Distance(latitude, longitude)
if __name__ == "__main__":
gui = GUI()
gui.main()