forked from Turonk/character_creation_module
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp3.py
More file actions
64 lines (46 loc) · 2.52 KB
/
Copy pathtemp3.py
File metadata and controls
64 lines (46 loc) · 2.52 KB
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
# импортируем функции из библиотеки math для рассчёта расстояния
from math import radians, sin, cos, acos
class Point:
def __init__(self, latitude, longitude):
self.latitude = radians(latitude)
self.longitude = radians(longitude)
# считаем расстояние между двумя точками в км
def distance(self, other):
cos_d = sin(self.latitude) * sin(other.latitude) + cos(self.latitude) * cos(other.latitude) * cos(
self.longitude - other.longitude)
return 6371 * acos(cos_d)
class City(Point):
def __init__(self, latitude, longitude, name, population):
# допишите код: сохраните свойства родителя
# и добавьте свойства name и population
super().__init__(latitude, longitude)
self.name = name
self.population = population
def show(self):
print(f"Город {self.name}, население {self.population} чел.")
class Mountain(Point):
# допишите код: напишите конструктор, в нём сохраните свойства родителя
# и добавьте свойства name и height
def __init__(self, latitude, longitude, name, height):
# допишите код: сохраните свойства родителя
# и добавьте свойства name и population
super().__init__(latitude, longitude)
self.name = name
self.height = height
def show(self):
print(f"Высота горы {self.name} - {self.height} м.")
# Создайте метод show(self):
# информацию о горе нужно вывести в формате:
# "Высота горы <название> - <высота> м."
# эта функция печатает расстояние
# между двумя любыми наследниками класса Point
def print_how_far(geo_object_1, geo_object_2):
print(f'От точки «{geo_object_1.name}» до точки «{geo_object_2.name}» — {geo_object_1.distance(geo_object_2)} км.')
# основной код
moscow = City(55.7522200, 37.6155600, 'Москва', 12615882)
everest = Mountain(27.98791, 86.92529, 'Эверест', 8848)
chelyabinsk = City(55.154, 61.4291, 'Челябинск', 1200703)
moscow.show()
everest.show()
print_how_far(moscow, everest)
print_how_far(moscow, chelyabinsk)