Solution 1

class Car(object):
    def __init__(self, electric):
        self.electric = electric

    def drive(self):
        if self.electric:
            return 'WHIRRRRRRR'
        return 'VROOOOM'

Make a Car that can Drive!

Create a class Car that is initialized by providing one mandatory argument: electric.
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(  # 'VROOOOM'

car2 = Car(electric=True)
print(car2.electric)  # True
print(  # 'WHIRRRRRRR'

Test Cases

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 == '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 == 'WHIRRRRRRR'