Skip to content

Car

Car

Bases: Vehicle

A car class which inherits from Vehicle.

Source code in src/car.py
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class Car(Vehicle):
    '''
    A car class which inherits from Vehicle.
    '''
    def __init__(self, num_of_wheels: int, brand: str):
        '''
        Initialise a car with the given number of wheels.

        Args:
            num_of_wheels (int): the number of wheels a vehicle has
        '''
        super().__init__(num_of_wheels)
        self._brand = brand


    @property
    def brand(self) -> str:
        '''
        Return the brand of the car.

        Returns:
            str: the brand of the car
        '''
        return self._brand

    def drive(self, num_of_miles: float) -> None:
        '''
        Drive the vehicle for a given number of miles

        Args:
            num_of_miles (float): how far to drive the vehicle
        '''
        print('starting engine')
        print(f'driving forward for {num_of_miles} mile(s)')
        print('stopping')

brand: str property

Return the brand of the car.

Returns:

Name Type Description
str str

the brand of the car

__init__(num_of_wheels, brand)

Initialise a car with the given number of wheels.

Parameters:

Name Type Description Default
num_of_wheels int

the number of wheels a vehicle has

required
Source code in src/car.py
 7
 8
 9
10
11
12
13
14
15
def __init__(self, num_of_wheels: int, brand: str):
    '''
    Initialise a car with the given number of wheels.

    Args:
        num_of_wheels (int): the number of wheels a vehicle has
    '''
    super().__init__(num_of_wheels)
    self._brand = brand

drive(num_of_miles)

Drive the vehicle for a given number of miles

Parameters:

Name Type Description Default
num_of_miles float

how far to drive the vehicle

required
Source code in src/car.py
28
29
30
31
32
33
34
35
36
37
def drive(self, num_of_miles: float) -> None:
    '''
    Drive the vehicle for a given number of miles

    Args:
        num_of_miles (float): how far to drive the vehicle
    '''
    print('starting engine')
    print(f'driving forward for {num_of_miles} mile(s)')
    print('stopping')