Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ celerybeat.pid
# Environments
.env
.venv
.venv/
env/
venv/
ENV/
Expand Down
111 changes: 100 additions & 11 deletions homework.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,148 @@
from pyexpat.errors import messages


class InfoMessage:
"""Информационное сообщение о тренировке."""
pass
def __init__(self,
training_type: str,
duration: float,
distance: float,
speed: float,
calories: float) -> None:
self.training_type = training_type
self.duration = duration
self.distance = distance
self.speed = speed
self.calories = calories

def get_message(self) -> str:
message_result = (f'Тип тренировки: {self.training_type}; '
f'Длительность: {self.duration:.3f} ч.; '
f'Дистанция: {self.distance:.3f} км; '
f'Ср. скорость: {self.speed:.3f} км/ч; '
f'Потрачено ккал: {self.calories:.3f}.')
return message_result


class Training:
"""Базовый класс тренировки."""

LEN_STEP = 0.65
M_IN_KM = 1000
MIN_IN_H = 60

def __init__(self,
action: int,
duration: float,
weight: float,
) -> None:
pass
self.action = action
self.duration = duration
self.weight = weight

def get_distance(self) -> float:
"""Получить дистанцию в км."""
pass
return self.action * self.LEN_STEP / self.M_IN_KM

def get_mean_speed(self) -> float:
"""Получить среднюю скорость движения."""
pass
return self.get_distance() / self.duration

def get_spent_calories(self) -> float:
"""Получить количество затраченных калорий."""
pass

def show_training_info(self) -> InfoMessage:
"""Вернуть информационное сообщение о выполненной тренировке."""
pass
info = InfoMessage(
training_type=self.__class__.__name__,
duration=self.duration,
distance=self.get_distance(),
speed=self.get_mean_speed(),
calories=self.get_spent_calories()
)
return info


class Running(Training):
"""Тренировка: бег."""
pass

CALORIES_MEAN_SPEED_MULTIPLIER = 18
CALORIES_MEAN_SPEED_SHIFT = 1.79

def get_spent_calories(self) -> float:
"""Получить количество затраченных калорий при беге."""
return ((self.CALORIES_MEAN_SPEED_MULTIPLIER * self.get_mean_speed()
+ self.CALORIES_MEAN_SPEED_SHIFT)
* self.weight / self.M_IN_KM * self.duration * self.MIN_IN_H)


class SportsWalking(Training):
"""Тренировка: спортивная ходьба."""
pass

CALORIES_WEIGHT_COEFFICIENT = 0.035
CALORIES_WEIGHT_SPEED_COEFFICIENT = 0.029
SM_IN_M = 100
KM_H_IN_M_S = 0.278

def __init__(self,
action: int,
duration: float,
weight: float,
height: float
) -> None:
super().__init__(action, duration, weight)
self.height = height

def get_spent_calories(self) -> float:
"""Получить количество затраченных калорий при спортивной ходьбе."""
return ((self.CALORIES_WEIGHT_COEFFICIENT * self.weight
+ ((self.get_mean_speed() * self.KM_H_IN_M_S) ** 2
/ (self.height / self.SM_IN_M))
* self.CALORIES_WEIGHT_SPEED_COEFFICIENT
* self.weight) * self.duration * self.MIN_IN_H)


class Swimming(Training):
"""Тренировка: плавание."""
pass

LEN_STEP = 1.38
MEAN_SPEED_MULTIPLIER = 1.1
CALORIES_SPEED_MULTIPLIER = 2

def __init__(self,
action: int,
duration: float,
weight: float,
length_pool,
count_pool
) -> None:
super().__init__(action, duration, weight)
self.length_pool = length_pool
self.count_pool = count_pool

def get_mean_speed(self) -> float:
return (self.length_pool * self.count_pool
/ self.M_IN_KM / self.duration)

def get_spent_calories(self) -> float:
return ((self.get_mean_speed() + self.MEAN_SPEED_MULTIPLIER)
* self.CALORIES_SPEED_MULTIPLIER * self.weight * self.duration)


def read_package(workout_type: str, data: list) -> Training:
"""Прочитать данные полученные от датчиков."""
pass
workout_type_dict = {'SWM': Swimming,
'RUN': Running,
'WLK': SportsWalking}
result = workout_type_dict[workout_type](*data)
return result


def main(training: Training) -> None:
"""Главная функция."""
pass
info = training.show_training_info()
print(info.get_message())


if __name__ == '__main__':
Expand All @@ -65,4 +155,3 @@ def main(training: Training) -> None:
for workout_type, data in packages:
training = read_package(workout_type, data)
main(training)