Why does letting `get_calories` estimate a missing value force a class variable and datetime objects into the class?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Every Swim burns 500 calories per hour, and that one rate is shared by every swim ever created — nothing ever changes it. Add it to the class below as a class variable named cal_per_hr, in the class body and outside every method. The checks read Swim.cal_per_hr and read the same name on an instance.
The cal_per_hr class variable
State the two ways a workout gets its calories, supplied by the user or estimated from the duration, and write cal_per_hr = 200 as a class variable nothing here ever modifies.
A None default and parsed start and end times
Write def __init__(self, start, end, calories=None): together with self.start = parser.parse(start) and self.end = parser.parse(end), and record that the stored values are datetime objects, not the strings passed in.
A getter written as a two-branch switch
Write the if (self.calories == None) branch returning Workout.cal_per_hr * (self.end - self.start).total_seconds() / 3600.0, the else returning the supplied number, and name the timedelta the subtraction produces.