Is Amphibian a Boat or a Car?
Imagine a world where our transportation is not just confined to roads or waters but can be both. In this innovative setting, we need a transport device that can function both on roads and on water bodies.
To meet this need, you are tasked to design two base classes
Car
and Boat
, and a derived class Amphibian
, which will inherit from both base classes.
The
Car
class should have a method drive(distance)
, that when invoked, increases the car's odometer reading by the given distance and returns the new reading.The
Boat
class should have a method sail(distance)
, that when invoked, increases the boat's odometer reading by the given distance and returns the new reading.The
Amphibian
class should inherit the drive()
and sail()
methods, and should be able to invoke both. It should also keep track of the total distance traveled, whether by road or water.The
total_distance()
method should return the total distance covered by the amphibian vehicle, combining the distances covered on road and water.Input | Output |
amphibian=Amphibian(); print(amphibian.drive(100)); print(amphibian.sail(200)); print(amphibian.total_distance()) | 100
300
300 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB