Make a car that can drive!
Create a class
Car that is initialized by providing one mandatory argument:
It will have a method called
drive that returns the sound the car makes.
Make sure the text for the sound output matches the example.
You can access the attributes in the
drive method from the self variable.
car1 = Car(electric=False) print(car1.electric) # False print(car1.drive()) # 'VROOOOM' car2 = Car(electric=True) print(car2.electric) # True print(car2.drive()) # 'WHIRRRRRRR'
test drive not electric - Run Test
def test_drive_not_electric(): car1 = Car(electric=False) assert isinstance(car1, object) is True assert hasattr(car1, 'electric') is True assert car1.electric is False assert car1.drive() == 'VROOOOM'
test drive electric - Run Test
def test_drive_electric(): car2 = Car(electric=True) assert isinstance(car2, object) is True assert hasattr(car2, 'electric') is True assert car2.electric is True assert car2.drive() == 'WHIRRRRRRR'