Statement:
Implement two vehicle classes:
Car:
- The constructor for car must take two arguments. The first of them is it's maximum speed and the second one is a string that denotes the units in which speed is given: either "Km/h" or "mph".
- The class must be implemented to return a string based on the arguments. For example, if car is an object of class car with a maximum speed of 120, and the unit is "Km/h", then the printing car prints the following string: "Car with the maximum speed of 120 Km/h", without quotes. If the maximum speed is 94 and the unit is "mph", then printing prints in the following string: "Car with the maximum speed of 94 mph", without quotes.
Boat:
- The constructor for boat must take a single argument denoting it's maximum speed in knots.
- The class must be implemented to return a string based on the argument for example, if boat is an object of class Boat with a maximum speed of 82, then printing boat prints the following string: "Boat with the maximum speed of 82 knots:, without quotes.
The implementation of the classes will be tested by a provided code stub on Several input files. Each input files contain several queries.
Solution:
1 2 3 4 5 6 7 8 9 | class Car: def __new__(self, speed,units): return "Car with the maximum speed of {0} {1}".format(speed, units) class Boat: def __new__(self,speed): return "Boat with the maximum speed of {0} knots".format(speed) |
Note: This solution is only for your reference and providing knowledge about the topic. Please don't just copy paste the solution.
Labels : #hackerrank certification ,#python (basic) ,