What exactly does the single line `super().__init__(start, end, calories)` do before `RunWorkout` overrides the icon and adds elevation?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
The Workout class from the earlier videos is given above. Give it a subclass for running that has no body of its own yet, then build one from the two time strings '8:00' and '8:45' — the parent's constructor is already there to do it. Define the class RunWorkout and assign the object you build to run.
# The Workout parent class from the earlier videos of this unit,
# with the times kept as plain strings and the icons as plain words.
class Workout(object):
cal_per_hr = 200
def __init__(self, start, end, calories=None):
self.start = start
self.end = end
self.calories = calories
self.icon = 'sweat'
self.kind = 'Workout'
def get_calories(self):
return self.calories
def get_kind(self):
return self.kindParent, subclass, and the three things a subclass brings
State that a child class is its parent, an outdoor workout is a workout, and list the three contributions of a subclass: added attributes, added behaviours and overridden behaviours.
A signature with elevation slipped in before calories
Write class RunWorkout(Workout): and def __init__(self, start, end, elev=0, calories=None, route_gps_points=None):, and record the six data attributes and the two argument patterns that build one.
Reusing the parent's constructor in one line
Write super().__init__(start,end,calories) beside its equivalent Workout.__init__(self, start, end, calories), then the overridden icon, self.kind = 'Running', the new self.elev, and get_elev with set_elev.