Object-oriented programming · 19 / 26 Exercise Medium

Interfaces

Objective

Develop a Python program that implements an interface called IVehicle. In Python an interface is an abstract class (abc.ABC) whose methods are all abstract.

Instructions

  • IVehicle has two methods: drive(), which displays nothing and returns nothing, and refuel(gasoline_amount), which receives the amount of gasoline and returns True or False.
  • Create a class Car that implements IVehicle. Its constructor receives the initial amount of gasoline.
  • drive() shows that the car is driving if the gasoline is greater than 0.
  • refuel() increases the gasoline of the car and returns True.
  • In the main program, create a Car with 0 gasoline, ask the user for the amount of gasoline to refuel, refuel the car and finally call drive().
Input
15
Output
Refueling successful. Current gasoline level: 15
Attempting to drive the car:
The car is driving.

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise