Given the specs you describe for your homework (there must be a getName()
command which returns the name of the robot (as a string) which will be overridden in the subclass) the existing answer showing a special method __str__
is unlikely to help -- they are pretty weird and unPythonic specs, but, hey, homework is homework, after all, not real life.
So I imagine they want you to code in the base class something like:
class RobotBase(object):
def getName(self):
return "GenericRobot"
# and other methods &c
and in each subclass have a different override of this, such as
class RobotShiny(RobotBase):
def getName(self):
return "ShinyRobot"
class RobotShady(RobotBase):
def getName(self):
return "ShadowRobot"
and so forth/