Module for calculating and displaying complete information about training according to data from the sensor unit.
Implement a module according to the OOP methodology for calculating and displaying information about the past training according to the data from the sensor unit.
class Training
- action - the main readable action during training (step - running, walking; stroke - swimming);
- duration - the duration of the workout;
- weight — athlete's weight;
- M_IN_KM = 1000 - constant for converting values from meters to kilometers;
- LEN_STEP - the distance that the athlete overcomes in one step or stroke. One step is
0.65
meters, one stroke is1.38
meters.
- get_distance() - the method returns the value of the distance covered during the training.
# basic calculation formula
step * LEN_STEP / M_IN_KM
- get_mean_speed() - method returns the value of the average movement speed during training.
# basic calculation formula
distance / duration
- get_spent_calories() - method returns the number of calories burned.
- show_training_info() - method returns a message class object.
Running class
class Running
inherited
override method:
- get_spent_calories() - method returns the number of calories burned.
# calculation formula
(18 * average_speed - 20) * athlete_weight / M_IN_KM * training_time_in_minutes
Walking class
class SportsWalking
Added properties:
- height - height
override method:
- get_spent_calories() - method returns the number of calories burned.
# calculation formula
(0.035 * weight + (speed ** 2 // height) * 0.029 * weight) * workout_time_minutes
Pool workout class
class Swimming
Added properties:
- length_pool — pool length;
- count_pool - the number of swimming pools.
override method:
- get_mean_speed() - method returns the value of the average movement speed during training.
# calculation formula
pool_length * count_pool / M_IN_KM / training_time
- get_spent_calories() - method returns the number of calories burned.
# calculation formula
(speed + 1.1) * 2 * weight
class InfoMessage
- training_type — training type;
- duration - the duration of the workout;
- distance — distance covered during the workout;
- speed - average speed of movement; *calories - calories burned during the workout.
- get_message() - method returns a message string.
# output message
# all float values are rounded to 3 decimal places
'Training type: {training_type}; Duration: {duration} hours; Distance: {distance} km; Wed speed: {speed} km/h; Calories burned: {calories}'.
def read_package()
- The read_package() function takes as input a training code and a list of its parameters.
- The function must determine the type of training and create an object of the appropriate class, passing to it the parameters received in the second argument. The function must return this object.
def main(training)
The main()
function must take an instance of the Training
class as input.
– When executing the main()
function, the show_training_info()
method must be called for this instance;
the result of the method execution must be an object of the InfoMessage
class, it must be stored in the info
variable.
– For the InfoMessage
object stored in the info
variable, the method must be called
which will return a message string with training data; this string must be passed to the print()
function.